Path: blob/master/test/hotspot/jtreg/compiler/cha/AbstractRootMethod.java
41149 views
/*1* Copyright (c) 2021, 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* @requires !vm.graal.enabled & vm.opt.final.UseVtableBasedCHA == true26* @modules java.base/jdk.internal.org.objectweb.asm27* java.base/jdk.internal.misc28* java.base/jdk.internal.vm.annotation29* @library /test/lib /30* @compile Utils.java31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33*34* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions35* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet36* -XX:CompileCommand=compileonly,*::m37* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test38* -Xbatch -Xmixed -XX:+WhiteBoxAPI39* -XX:-TieredCompilation40* compiler.cha.AbstractRootMethod41*42* @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions43* -XX:+PrintCompilation -XX:+PrintInlining -XX:+TraceDependencies -verbose:class -XX:CompileCommand=quiet44* -XX:CompileCommand=compileonly,*::m45* -XX:CompileCommand=compileonly,*::test -XX:CompileCommand=dontinline,*::test46* -Xbatch -Xmixed -XX:+WhiteBoxAPI47* -XX:+TieredCompilation -XX:TieredStopAtLevel=148* compiler.cha.AbstractRootMethod49*/50package compiler.cha;5152import static compiler.cha.Utils.*;5354public class AbstractRootMethod {55public static void main(String[] args) {56run(AbstractClass.class);57run(AbstractInterface.class);58}5960public static class AbstractClass extends ATest<AbstractClass.C> {61public AbstractClass() {62super(C.class, D.class);63}6465interface I1 { Object m(); }66interface I2 { default Object m() { return "I2.m"; } }6768static abstract class C { public abstract Object m(); }6970static abstract class D extends C {71final Object ret = CORRECT;72public Object m() {73return ret;74}75}7677static abstract class E1 extends C { /* empty */ }78static abstract class E2 extends C { public abstract Object m(); }79static abstract class E3 extends C { public Object m() { return "E3.m"; } }8081static abstract class F1 extends C implements I1 { }82static abstract class F2 extends C implements I2 { }8384static class G extends C { public Object m() { return CORRECT; } }8586@Override87public Object test(C obj) {88return obj.m(); // invokevirtual C.m()89}9091@Override92public void checkInvalidReceiver() {93// nothing to do: concrete class types are enforced by the verifier94}9596@TestCase97public void test() {98// 0. Trigger compilation of a megamorphic call site99compile(megamorphic()); // Dn <: D.m <: C.m ABSTRACT100assertCompiled();101102// Dependency: type = unique_concrete_method, context = C, method = D.m103104// 1. No invalidation: abstract classes don't participate in CHA.105initialize(E1.class, // ABSTRACT E1 <: C.m ABSTRACT106E2.class, // ABSTRACT E2.m ABSTRACT <: C.m ABSTRACT107E3.class, // ABSTRACT E3.m <: C.m ABSTRACT108F1.class, // ABSTRACT F1 <: C.m ABSTRACT, I1.m ABSTRACT109F2.class); // ABSTRACT F2 <: C.m ABSTRACT, I2.m DEFAULT110assertCompiled();111112// 2. Dependency invalidation: G.m <: C.m ABSTRACT113load(G.class);114assertCompiled();115116// 3. Dependency invalidation: G.m <: C.m ABSTRACT117initialize(G.class);118assertNotCompiled();119120// 4. Recompilation: no inlining, no dependencies121compile(megamorphic());122call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C.m ABSTRACT123call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C.m ABSTRACT124assertCompiled();125}126}127public static class AbstractInterface extends ATest<AbstractInterface.C> {128public AbstractInterface() {129super(C.class, D.class);130}131132interface I1 { Object m(); }133interface I2 extends I { default Object m() { return "I2.m"; } }134135interface I { Object m(); }136137static abstract class C implements I { /* inherited from I */}138139static abstract class D extends C {140final Object ret = CORRECT;141public Object m() {142return ret;143}144}145146static abstract class E1 extends C { /* empty */ }147static abstract class E2 extends C { public abstract Object m(); }148static abstract class E3 extends C { public Object m() { return "E3.m"; } }149150static abstract class F1 extends C implements I1 { }151static abstract class F2 extends C implements I2 { }152153static class G extends C { public Object m() { return CORRECT; } }154155@Override156public Object test(C obj) {157return obj.m(); // invokevirtual C.m()158}159160@Override161public void checkInvalidReceiver() {162// nothing to do: concrete class types are enforced by the verifier163}164165@TestCase166public void test() {167// 0. Trigger compilation of a megamorphic call site168compile(megamorphic()); // Dn <: D.m <: C <: I.m ABSTRACT169assertCompiled();170171// Dependency: type = unique_concrete_method, context = C, method = D.m172173// 1. No invalidation: abstract classes don't participate in CHA.174initialize(E1.class, // ABSTRACT E1 <: C <: I.m ABSTRACT175E2.class, // ABSTRACT E2.m ABSTRACT <: C <: I.m ABSTRACT176E3.class, // ABSTRACT E3.m <: C <: I.m ABSTRACT177F1.class, // ABSTRACT F1 <: C <: I.m ABSTRACT, I1.m ABSTRACT178F2.class); // ABSTRACT F2 <: C <: I.m ABSTRACT, I2.m DEFAULT179assertCompiled();180181// 2. Dependency invalidation: G.m <: C <: I.m ABSTRACT182load(G.class);183assertCompiled();184185// 3. Dependency invalidation: G.m <: C <: I.m ABSTRACT186initialize(G.class);187assertNotCompiled();188189// 4. Recompilation: no inlining, no dependencies190compile(megamorphic());191call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C <: I.m ABSTRACT192call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C <: I.m ABSTRACT193assertCompiled();194}195}196}197198199