HasFinalizableSubclassTest.java revision 12365:d1a00bd8dcca
1118611Snjl/* 2118611Snjl * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3118611Snjl * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4118611Snjl * 5118611Snjl * This code is free software; you can redistribute it and/or modify it 6118611Snjl * under the terms of the GNU General Public License version 2 only, as 7118611Snjl * published by the Free Software Foundation. 8118611Snjl * 9118611Snjl * This code is distributed in the hope that it will be useful, but WITHOUT 10118611Snjl * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11118611Snjl * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12118611Snjl * version 2 for more details (a copy is included in the LICENSE file that 13118611Snjl * accompanied this code). 14118611Snjl * 15118611Snjl * You should have received a copy of the GNU General Public License version 16118611Snjl * 2 along with this work; if not, write to the Free Software Foundation, 17118611Snjl * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18118611Snjl * 19118611Snjl * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20118611Snjl * or visit www.oracle.com if you need additional information or have any 21118611Snjl * questions. 22118611Snjl */ 23118611Snjl 24118611Snjl/* 25118611Snjl * @test 26118611Snjl * @bug 8136421 27118611Snjl * @requires vm.jvmci 28118611Snjl * @library / /test/lib 29118611Snjl * @library ../common/patches 30118611Snjl * @modules java.base/jdk.internal.misc 31118611Snjl * @modules jdk.vm.ci/jdk.vm.ci.hotspot 32118611Snjl * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper 33118611Snjl * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 34118611Snjl * compiler.jvmci.compilerToVM.HasFinalizableSubclassTest 35118611Snjl */ 36118611Snjl 37118611Snjlpackage compiler.jvmci.compilerToVM; 38118611Snjl 39118611Snjlimport compiler.jvmci.common.testcases.AbstractClass; 40118611Snjlimport compiler.jvmci.common.testcases.AbstractClassExtender; 41118611Snjlimport compiler.jvmci.common.testcases.DoNotImplementInterface; 42118611Snjlimport compiler.jvmci.common.testcases.MultipleImplementer1; 43118611Snjlimport compiler.jvmci.common.testcases.MultipleImplementersInterface; 44118611Snjlimport compiler.jvmci.common.testcases.SingleImplementerInterface; 45118611Snjlimport jdk.test.lib.Asserts; 46118611Snjlimport jdk.test.lib.Utils; 47118611Snjlimport jdk.vm.ci.hotspot.CompilerToVMHelper; 48118611Snjlimport jdk.vm.ci.hotspot.HotSpotResolvedObjectType; 49118611Snjl 50118611Snjlimport java.util.HashSet; 51118611Snjlimport java.util.Set; 52118611Snjlimport java.util.stream.Stream; 53118611Snjl 54118611Snjlpublic class HasFinalizableSubclassTest { 55118611Snjl public static void main(String args[]) { 56118611Snjl HasFinalizableSubclassTest test = new HasFinalizableSubclassTest(); 57118611Snjl for (TestCase tcase : createTestCases()) { 58118611Snjl test.runTest(tcase); 59118611Snjl } 60118611Snjl } 61118611Snjl 62118611Snjl private static Set<TestCase> createTestCases() { 63118611Snjl Stream.of( 64118611Snjl AbstractClassExtender.class, 65118611Snjl SingleImplementerInterface.class, 66118611Snjl MultipleImplementersInterface.class, 67118611Snjl MultipleImplementer1.class, 68118611Snjl DoNotImplementInterface.class) 69118611Snjl .forEach(Utils::ensureClassIsLoaded); 70118611Snjl Set<TestCase> result = new HashSet<>(); 71118611Snjl // iface with finalize method 72118611Snjl result.add(new TestCase(SingleImplementerInterface.class, false)); 73118611Snjl // iface with default finalize method 74118611Snjl result.add(new TestCase(MultipleImplementersInterface.class, false)); 75118611Snjl // class which implements iface w/ default finalize method 76118611Snjl result.add(new TestCase(MultipleImplementer1.class, true)); 77118611Snjl // abstract class with finalizeable subclass 78118611Snjl result.add(new TestCase(AbstractClass.class, true)); 79118611Snjl // non-implemented iface 80118611Snjl result.add(new TestCase(DoNotImplementInterface.class, false)); 81118611Snjl return result; 82118611Snjl } 83118611Snjl 84118611Snjl private void runTest(TestCase tcase) { 85118611Snjl System.out.println(tcase); 86118611Snjl HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper 87118611Snjl .lookupType(Utils.toJVMTypeSignature(tcase.aClass), 88118611Snjl getClass(), /* resolve = */ true); 89118611Snjl Asserts.assertEQ(tcase.expected, 90118611Snjl CompilerToVMHelper.hasFinalizableSubclass(metaspaceKlass), 91118611Snjl "Unexpected finalizableSubclass state for " 92118611Snjl + tcase.aClass.getName()); 93118611Snjl } 94118611Snjl 95118611Snjl private static class TestCase { 96118611Snjl public final Class<?> aClass; 97118611Snjl public final boolean expected; 98118611Snjl 99118611Snjl public TestCase(Class<?> clazz, boolean expected) { 100118611Snjl this.aClass = clazz; 101118611Snjl this.expected = expected; 102118611Snjl } 103118611Snjl @Override 104118611Snjl public String toString() { 105118611Snjl return "CASE: class= " + aClass.getName() + ", expected=" + expected; 106118611Snjl } 107118611Snjl } 108118611Snjl} 109118611Snjl