hotspot/test/compiler/jvmci/compilerToVM/HasFinalizableSubclassTest.java
author lmesnik
Fri, 17 Jun 2016 13:07:27 +0300
changeset 39291 a4efe145313d
parent 38152 80e5da81fb2c
child 40059 c2304140ed64
permissions -rw-r--r--
8157831: JVMCI tests should not be executed on linux-arm32 Reviewed-by: dpochepk, dholmes
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
/*
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
39291
a4efe145313d 8157831: JVMCI tests should not be executed on linux-arm32
lmesnik
parents: 38152
diff changeset
    27
 * @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64")
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 33160
diff changeset
    28
 * @library / /testlibrary /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
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    31
 * @modules jdk.vm.ci/jdk.vm.ci.hotspot
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    32
 * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    33
 * @build compiler.jvmci.compilerToVM.HasFinalizableSubclassTest
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    34
 * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    35
 *                  compiler.jvmci.compilerToVM.HasFinalizableSubclassTest
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    37
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    38
package compiler.jvmci.compilerToVM;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    40
import compiler.jvmci.common.testcases.AbstractClass;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    41
import compiler.jvmci.common.testcases.AbstractClassExtender;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    42
import compiler.jvmci.common.testcases.DoNotImplementInterface;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    43
import compiler.jvmci.common.testcases.MultipleImplementer1;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    44
import compiler.jvmci.common.testcases.MultipleImplementersInterface;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    45
import compiler.jvmci.common.testcases.SingleImplementerInterface;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    46
import java.util.HashSet;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
import java.util.Set;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    48
import java.util.stream.Stream;
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.HotSpotResolvedObjectType;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
import jdk.test.lib.Asserts;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
import jdk.test.lib.Utils;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
public class HasFinalizableSubclassTest {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
    public static void main(String args[]) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
        HasFinalizableSubclassTest test = new HasFinalizableSubclassTest();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
        for (TestCase tcase : createTestCases()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
            test.runTest(tcase);
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
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    62
    private static Set<TestCase> createTestCases() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    63
        Stream.of(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
                    AbstractClassExtender.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
                    SingleImplementerInterface.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
                    MultipleImplementersInterface.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
                    MultipleImplementer1.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
                    DoNotImplementInterface.class)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    69
                .forEach(Utils::ensureClassIsLoaded);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    70
        Set<TestCase> result = new HashSet<>();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    71
        // iface with finalize method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
        result.add(new TestCase(SingleImplementerInterface.class, false));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
        // iface with default finalize method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    74
        result.add(new TestCase(MultipleImplementersInterface.class, false));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
        // class which implements iface w/ default finalize method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
        result.add(new TestCase(MultipleImplementer1.class, true));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
        // abstract class with finalizeable subclass
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
        result.add(new TestCase(AbstractClass.class, true));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    79
        // non-implemented iface
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    80
        result.add(new TestCase(DoNotImplementInterface.class, false));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    81
        return result;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    82
    }
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
    private void runTest(TestCase tcase) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
        System.out.println(tcase);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    86
        HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
                .lookupType(Utils.toJVMTypeSignature(tcase.aClass),
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    88
                        getClass(), /* resolve = */ true);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    89
        Asserts.assertEQ(tcase.expected,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    90
                CompilerToVMHelper.hasFinalizableSubclass(metaspaceKlass),
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    91
                        "Unexpected finalizableSubclass state for "
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    92
                                + tcase.aClass.getName());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    93
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    94
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    95
    private static class TestCase {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    96
        public final Class<?> aClass;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    97
        public final boolean expected;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    98
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
        public TestCase(Class<?> clazz, boolean expected) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
            this.aClass = clazz;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
            this.expected = expected;
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
        @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   104
        public String toString() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   105
            return "CASE: class= " + aClass.getName() + ", expected=" + expected;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   106
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   107
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   108
}