test/hotspot/jtreg/compiler/jvmci/compilerToVM/ResolvePossiblyCachedConstantInPoolTest.java
author mchung
Tue, 06 Nov 2018 10:01:16 -0800
changeset 52427 3c6aa484536c
parent 47216 71c04702a3d5
child 55206 2fe2063fe567
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8211122: Reduce the number of internal classes made accessible to jdk.unsupported Reviewed-by: alanb, dfuchs, kvn
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
/*
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
36306
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
 * @test
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    26
 * @bug 8138708
42607
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41705
diff changeset
    27
 * @requires vm.jvmci
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    28
 * @library /test/lib /
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    29
 * @library ../common/patches
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 47216
diff changeset
    30
 * @modules java.base/jdk.internal.access
37301
a936b4e01afb 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36508
diff changeset
    31
 *          java.base/jdk.internal.reflect
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    32
 *          java.base/jdk.internal.org.objectweb.asm
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    33
 *          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
    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.runtime
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    36
 *          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
    37
 *
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    38
 * @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
    39
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
b3617982544e 8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents: 39450
diff changeset
    40
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
36306
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    41
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    42
 *                   -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
44836
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    43
 *                   -Djvmci.Compiler=null
36306
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    44
 *                   compiler.jvmci.compilerToVM.ResolvePossiblyCachedConstantInPoolTest
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    45
 */
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
package compiler.jvmci.compilerToVM;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    48
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    49
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    50
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    51
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    52
import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
36306
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    53
import jdk.test.lib.Asserts;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    54
import jdk.vm.ci.hotspot.CompilerToVMHelper;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    55
import jdk.vm.ci.meta.ConstantPool;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    56
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    57
import java.util.HashMap;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    58
import java.util.Map;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    59
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    60
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_STRING;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    61
36306
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.resolvePossiblyCachedConstantInPool} 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 ResolvePossiblyCachedConstantInPoolTest {
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_STRING, ResolvePossiblyCachedConstantInPoolTest::validateString);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    70
        ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    71
        // The next "Class.forName" is here for the following reason.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    72
        // When class is initialized, constant pool cache is available.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    73
        // This method works only with cached constant pool.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    74
        for (DummyClasses dummy : DummyClasses.values()) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    75
            Class.forName(dummy.klass.getName());
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    76
        }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    77
        testCase.test();
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    78
    }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    79
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    80
    private static void validateString(ConstantPool constantPoolCTVM,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    81
                                       ConstantTypes cpType,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    82
                                       DummyClasses dummyClass,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    83
                                       int cpi) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    84
        TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    85
        if (entry == null) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    86
            return;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    87
        }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    88
        int index = cpi;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    89
        String cached = "";
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    90
        int cpci = dummyClass.getCPCacheIndex(cpi);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    91
        if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    92
            index = cpci;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    93
            cached = "cached ";
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    94
        }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    95
        Object constantInPool = CompilerToVMHelper.resolvePossiblyCachedConstantInPool(constantPoolCTVM, index);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    96
        String stringToVerify = (String) constantInPool;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    97
        String stringToRefer = entry.name;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    98
        if (stringToRefer.equals("") && cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    99
            stringToRefer = null; // tested method returns null for cached empty strings
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
        String msg = String.format("Wrong string accessed by %sconstant pool index %d", cached, index);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   102
        Asserts.assertEQ(stringToRefer, stringToVerify, msg);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   103
    }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   104
}