Path: blob/master/test/hotspot/jtreg/compiler/cha/DefaultRootMethod.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.DefaultRootMethod41*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.DefaultRootMethod49*/50package compiler.cha;5152import static compiler.cha.Utils.*;5354public class DefaultRootMethod {55public static void main(String[] args) {56run(DefaultRoot.class);57run(InheritedDefault.class);58System.out.println("TEST PASSED");59}6061public static class DefaultRoot extends ATest<DefaultRoot.C> {62public DefaultRoot() {63super(C.class, D.class);64}6566interface I { default Object m() { return CORRECT; } }6768static class C implements I { /* inherited I.m */}6970static class D extends C { /* inherited I.m */ }7172static abstract class E1 extends C { /* empty */ }73static abstract class E2 extends C { public abstract Object m(); }74static abstract class E3 extends C { public Object m() { return "E3.m"; } }7576interface I1 extends I { Object m(); }77interface I2 extends I { default Object m() { return "I2.m"; } }7879static abstract class F1 extends C implements I1 { }80static abstract class F2 extends C implements I2 { }8182static class G extends C { public Object m() { return CORRECT; } }8384@Override85public Object test(C obj) {86return obj.m(); // invokevirtual C.m()87}8889@Override90public void checkInvalidReceiver() {91// nothing to do: concrete class types are enforced by the verifier92}9394@TestCase95public void test() {96// 0. Trigger compilation of a megamorphic call site97compile(megamorphic()); // Dn <: D.m <: C <: I.m DEFAULT98assertCompiled();99100// Dependency: type = unique_concrete_method, context = C, method = D.m101102// 1. No invalidation: abstract classes don't participate in CHA.103initialize(E1.class, // ABSTRACT E1 <: C <: I.m DEFAULT104E2.class, // ABSTRACT E2.m ABSTRACT <: C <: I.m DEFAULT105E3.class, // ABSTRACT E3.m <: C <: I.m DEFAULT106F1.class, // ABSTRACT F1 <: C <: I.m DEFAULT, I1.m ABSTRACT107F2.class); // ABSTRACT F2 <: C <: I.m DEFAULT, I2.m DEFAULT108assertCompiled();109110// 2. Dependency invalidation: G.m <: C <: I.m DEFAULT111load(G.class);112assertCompiled();113114// 3. Dependency invalidation: G.m <: C <: I.m DEFAULT115initialize(G.class);116assertNotCompiled();117118// 4. Recompilation: no inlining, no dependencies119compile(megamorphic());120call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C <: I.m DEFAULT121call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C <: I.m DEFAULT122assertCompiled();123}124}125126public static class InheritedDefault extends ATest<InheritedDefault.C> {127public InheritedDefault() {128super(C.class, D.class);129}130131interface I { Object m(); }132interface J extends I { default Object m() { return CORRECT; } }133134static abstract class C implements I { /* inherits I.m ABSTRACT */}135136// NB! The class is marked abstract to avoid abstract_with_unique_concrete_subtype dependency137static abstract class D extends C implements J { /* inherits J.m DEFAULT*/ }138139static abstract class E1 extends C { /* empty */ }140static abstract class E2 extends C { public abstract Object m(); }141static abstract class E3 extends C { public Object m() { return "E3.m"; } }142143interface I1 extends I { Object m(); }144interface I2 extends I { default Object m() { return "I2.m"; } }145146static abstract class F1 extends C implements I1 { }147static abstract class F2 extends C implements I2 { }148149interface K extends I { default Object m() { return CORRECT; } }150static class G extends C implements K { /* inherits K.m DEFAULT */ }151152@Override153public Object test(C obj) {154return obj.m(); // invokevirtual C.m()155}156157@Override158public void checkInvalidReceiver() {159// nothing to do: concrete class types are enforced by the verifier160}161162@TestCase163public void test() {164// 0. Trigger compilation of a megamorphic call site165compile(megamorphic()); // Dn <: D.m <: C <: I.m ABSTRACT, J.m DEFAULT166assertCompiled();167168// Dependency: type = unique_concrete_method, context = C, method = D.m169170// 1. No invalidation: abstract classes don't participate in CHA.171initialize(E1.class, // ABSTRACT E1 <: C <: I.m ABSTRACT172E2.class, // ABSTRACT E2.m ABSTRACT <: C <: I.m ABSTRACT173E3.class, // ABSTRACT E3.m <: C <: I.m ABSTRACT174F1.class, // ABSTRACT F1 <: C <: I.m ABSTRACT, I1.m ABSTRACT175F2.class); // ABSTRACT F2 <: C <: I.m ABSTRACT, I2.m DEFAULT176assertCompiled();177178// 2. No invalidation: not yet linked classes don't participate in CHA.179load(G.class);180assertCompiled();181182// 3. Dependency invalidation: G.m <: C <: I.m DEFAULT183initialize(G.class);184assertNotCompiled();185186// 4. Recompilation: no inlining, no dependencies187compile(megamorphic());188call(new C() { public Object m() { return CORRECT; } }); // Cn.m <: C <: I.m DEFAULT189call(new G() { public Object m() { return CORRECT; } }); // Gn <: G.m <: C <: I.m DEFAULT190assertCompiled();191}192}193}194195196