hotspot/test/compiler/jvmci/compilerToVM/HasFinalizableSubclassTest.java
author jprovino
Wed, 11 Nov 2015 23:47:41 +0000
changeset 33813 4f376e851453
parent 33632 038347770a9e
parent 33730 30e064828045
child 35148 5cfafc99d791
permissions -rw-r--r--
Merge
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
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    27
 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 33160
diff changeset
    28
 * @library / /testlibrary /test/lib
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    29
 * @compile ../common/CompilerToVMHelper.java
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    30
 * @build compiler.jvmci.compilerToVM.HasFinalizableSubclassTest
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    31
 * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockExperimentalVMOptions
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    33
 *     -XX:+EnableJVMCI compiler.jvmci.compilerToVM.HasFinalizableSubclassTest
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    34
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    35
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
package compiler.jvmci.compilerToVM;
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
import compiler.jvmci.common.testcases.AbstractClass;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
import compiler.jvmci.common.testcases.AbstractClassExtender;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    40
import compiler.jvmci.common.testcases.DoNotImplementInterface;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    41
import compiler.jvmci.common.testcases.MultipleImplementer1;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    42
import compiler.jvmci.common.testcases.MultipleImplementersInterface;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    43
import compiler.jvmci.common.testcases.SingleImplementerInterface;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    44
import java.util.HashSet;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    45
import java.util.Set;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    46
import java.util.stream.Stream;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
import jdk.vm.ci.hotspot.CompilerToVMHelper;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    48
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
import jdk.test.lib.Asserts;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    50
import jdk.test.lib.Utils;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
public class HasFinalizableSubclassTest {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
    public static void main(String args[]) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
        HasFinalizableSubclassTest test = new HasFinalizableSubclassTest();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
        for (TestCase tcase : createTestCases()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
            test.runTest(tcase);
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
    }
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
    private static Set<TestCase> createTestCases() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
        Stream.of(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    62
                    AbstractClassExtender.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    63
                    SingleImplementerInterface.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
                    MultipleImplementersInterface.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
                    MultipleImplementer1.class,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
                    DoNotImplementInterface.class)
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
                .forEach(Utils::ensureClassIsLoaded);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
        Set<TestCase> result = new HashSet<>();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    69
        // iface with finalize method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    70
        result.add(new TestCase(SingleImplementerInterface.class, false));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    71
        // iface with default finalize method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
        result.add(new TestCase(MultipleImplementersInterface.class, false));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
        // class which implements iface w/ default finalize method
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    74
        result.add(new TestCase(MultipleImplementer1.class, true));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
        // abstract class with finalizeable subclass
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
        result.add(new TestCase(AbstractClass.class, true));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
        // non-implemented iface
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
        result.add(new TestCase(DoNotImplementInterface.class, false));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    79
        return result;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    80
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    81
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    82
    private void runTest(TestCase tcase) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    83
        System.out.println(tcase);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    84
        HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
                .lookupType(Utils.toJVMTypeSignature(tcase.aClass),
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
                        getClass(), /* resolve = */ true);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
        Asserts.assertEQ(tcase.expected,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    88
                CompilerToVMHelper.hasFinalizableSubclass(metaspaceKlass),
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    89
                        "Unexpected finalizableSubclass state for "
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    90
                                + tcase.aClass.getName());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    91
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    92
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    93
    private static class TestCase {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    94
        public final Class<?> aClass;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    95
        public final boolean expected;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    96
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    97
        public TestCase(Class<?> clazz, boolean expected) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    98
            this.aClass = clazz;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
            this.expected = expected;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
        @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
        public String toString() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   103
            return "CASE: class= " + aClass.getName() + ", expected=" + expected;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   104
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   105
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   106
}