Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/HasFinalizableSubclassTest.java
41153 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813642126* @requires vm.jvmci27* @library / /test/lib28* @library ../common/patches29* @modules java.base/jdk.internal.misc30* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot31* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper32* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI33* -XX:-UseJVMCICompiler34* compiler.jvmci.compilerToVM.HasFinalizableSubclassTest35*/3637package compiler.jvmci.compilerToVM;3839import compiler.jvmci.common.testcases.AbstractClass;40import compiler.jvmci.common.testcases.AbstractClassExtender;41import compiler.jvmci.common.testcases.DoNotImplementInterface;42import compiler.jvmci.common.testcases.MultipleImplementer1;43import compiler.jvmci.common.testcases.MultipleImplementersInterface;44import compiler.jvmci.common.testcases.SingleImplementerInterface;45import jdk.test.lib.Asserts;46import jdk.test.lib.Utils;47import jdk.vm.ci.hotspot.CompilerToVMHelper;48import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;4950import java.util.HashSet;51import java.util.Set;52import java.util.stream.Stream;5354public class HasFinalizableSubclassTest {55public static void main(String args[]) {56HasFinalizableSubclassTest test = new HasFinalizableSubclassTest();57for (TestCase tcase : createTestCases()) {58test.runTest(tcase);59}60}6162private static Set<TestCase> createTestCases() {63Stream.of(64AbstractClassExtender.class,65SingleImplementerInterface.class,66MultipleImplementersInterface.class,67MultipleImplementer1.class,68DoNotImplementInterface.class)69.forEach(Utils::ensureClassIsLoaded);70Set<TestCase> result = new HashSet<>();71// iface with finalize method72result.add(new TestCase(SingleImplementerInterface.class, false));73// iface with default finalize method74result.add(new TestCase(MultipleImplementersInterface.class, false));75// class which implements iface w/ default finalize method76result.add(new TestCase(MultipleImplementer1.class, true));77// abstract class with finalizeable subclass78result.add(new TestCase(AbstractClass.class, true));79// non-implemented iface80result.add(new TestCase(DoNotImplementInterface.class, false));81return result;82}8384private void runTest(TestCase tcase) {85System.out.println(tcase);86HotSpotResolvedObjectType metaspaceKlass = CompilerToVMHelper87.lookupTypeHelper(Utils.toJVMTypeSignature(tcase.aClass),88getClass(), /* resolve = */ true);89Asserts.assertEQ(tcase.expected,90CompilerToVMHelper.hasFinalizableSubclass(metaspaceKlass),91"Unexpected finalizableSubclass state for "92+ tcase.aClass.getName());93}9495private static class TestCase {96public final Class<?> aClass;97public final boolean expected;9899public TestCase(Class<?> clazz, boolean expected) {100this.aClass = clazz;101this.expected = expected;102}103@Override104public String toString() {105return "CASE: class= " + aClass.getName() + ", expected=" + expected;106}107}108}109110111