test/hotspot/jtreg/compiler/jvmci/compilerToVM/GetConstantPoolTest.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 47216 71c04702a3d5
child 54669 ad45b3802d4e
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
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
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40372
diff changeset
     2
 * Copyright (c) 2015, 2016, 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
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40372
diff changeset
    28
 * @library /test/lib /
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    29
 * @library ../common/patches
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36508
diff changeset
    30
 * @modules java.base/jdk.internal.misc
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    31
 * @modules java.base/jdk.internal.org.objectweb.asm
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    32
 *          java.base/jdk.internal.org.objectweb.asm.tree
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    33
 *          jdk.internal.vm.ci/jdk.vm.ci.hotspot
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    34
 *          jdk.internal.vm.ci/jdk.vm.ci.meta
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
40053
b3617982544e 8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents: 39291
diff changeset
    36
 *
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    37
 * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    38
 * @run main/othervm -Xbootclasspath/a:.
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    39
 *                   -XX:+UnlockDiagnosticVMOptions
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    40
 *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
44836
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    41
 *                   -Djvmci.Compiler=null
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    42
 *                   compiler.jvmci.compilerToVM.GetConstantPoolTest
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    43
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    44
package compiler.jvmci.compilerToVM;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    45
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    46
import jdk.test.lib.Utils;
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    47
import compiler.jvmci.common.CTVMUtilities;
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    48
import compiler.jvmci.common.testcases.TestCase;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
import jdk.vm.ci.hotspot.CompilerToVMHelper;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    50
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    51
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    52
import jdk.vm.ci.meta.ConstantPool;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    53
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    54
import java.lang.reflect.Field;
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    55
import java.lang.reflect.Executable;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
/**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
 * Tests for jdk.vm.ci.hotspot.CompilerToVM::getConstantPool method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
public class GetConstantPoolTest {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    62
    public static void testMethod(Executable executable) {
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    63
        test(CTVMUtilities.getResolvedMethod(executable));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    66
    public static void testClass(Class cls) {
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    67
        HotSpotResolvedObjectType type = CompilerToVMHelper
46972
3e88de95fccf 8186459: [JVMCI] ClassNotFoundException thrown by CompilerToVM.lookupType() should be converted to a LinkageError
dnsimon
parents: 44836
diff changeset
    68
                .lookupTypeHelper(Utils.toJVMTypeSignature(cls),
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    69
                        GetConstantPoolTest.class, /* resolve = */ true);
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    70
        test(type);
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    71
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    73
    private static void test(Object object) {
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    74
        ConstantPool cp = CompilerToVMHelper.getConstantPool(object);
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    75
        System.out.println(object + " -> " + cp);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
    public static void main(String[] args) {
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    79
        TestCase.getAllClasses().forEach(GetConstantPoolTest::testClass);
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    80
        TestCase.getAllExecutables().forEach(GetConstantPoolTest::testMethod);
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    81
        testNull();
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    82
        testObject();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    83
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    85
    private static void testNull() {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
        try {
40372
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    87
            Object cp = CompilerToVMHelper.getConstantPool(null);
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    88
            throw new AssertionError("Test OBJECT."
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    89
                + " Expected IllegalArgumentException has not been caught");
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    90
        } catch (NullPointerException npe) {
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    91
            // expected
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    92
        }
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    93
    }
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    94
    private static void testObject() {
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    95
        try {
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    96
            Object cp = CompilerToVMHelper.getConstantPool(new Object());
ee472073dab0 8163105: SIGSEGV: constantPoolHandle::constantPoolHandle(ConstantPool*)
dnsimon
parents: 40059
diff changeset
    97
            throw new AssertionError("Test OBJECT."
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    98
                + " Expected IllegalArgumentException has not been caught");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
        } catch (IllegalArgumentException iae) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
            // expected
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   103
}