Path: blob/master/test/hotspot/jtreg/compiler/inlining/ResolvedClassTest.java
64474 views
/*1* Copyright (c) 2022, 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 827951526*27* @requires vm.flagless & vm.compiler1.enabled & vm.compiler2.enabled28* @modules java.base/jdk.internal.misc29* @library /test/lib /30*31* @run driver compiler.jsr292.ResolvedClassTest32*/3334package compiler.jsr292;3536import jdk.test.lib.process.OutputAnalyzer;37import jdk.test.lib.process.ProcessTools;3839import java.io.IOException;4041public class ResolvedClassTest {42/* ======================================================================== */43static void testStatic() throws IOException {44ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(45"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",46"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",47"-Xbatch", "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly," + TestStatic.class.getName() + "::test",48TestStatic.class.getName());4950OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());5152analyzer.shouldHaveExitValue(0);5354analyzer.shouldNotContain("TestStatic$A::m (1 bytes) not inlineable");55analyzer.shouldNotContain("TestStatic$A::m (1 bytes) no static binding");5657analyzer.shouldContain("TestStatic$A::m (1 bytes) inline");58}5960static class TestStatic {61static class A {62static void m() {}63}64static class B extends A {}6566// @DontInline67static void test() {68B.m(); // invokestatic B "m" => A::m69}7071public static void main(String[] args) {72for (int i = 0; i < 20_000; i++) {73test();74}75}76}7778/* ======================================================================== */79static void testStaticInit() throws IOException {80ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(81"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",82"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",83"-Xbatch", "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly," + TestStaticInit.class.getName() + "::test",84TestStaticInit.class.getName());8586OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());8788analyzer.shouldHaveExitValue(0);8990analyzer.shouldContain("TestStaticInit$A::m (1 bytes) no static binding");91}9293static class TestStaticInit {94static class A {95static {96for (int i = 0; i < 20_000; i++) {97TestStaticInit.test();98}99}100101static void m() {}102}103static class B extends A {}104105// @DontInline106static void test() {107B.m(); // A::<clinit> => test() => A::m()108}109110public static void main(String[] args) {111A.m(); // trigger initialization of A112}113}114115/* ======================================================================== */116static void testIndy() throws IOException {117ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(118"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",119"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",120"-Xbatch", "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly," + TestIndy.class.getName() + "::test",121TestIndy.class.getName());122123OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());124125analyzer.shouldHaveExitValue(0);126127analyzer.shouldNotMatch("java\\.lang\\.invoke\\..+::linkToTargetMethod \\(9 bytes\\) not inlineable");128129analyzer.shouldMatch("java\\.lang\\.invoke\\..+::linkToTargetMethod \\(9 bytes\\) force inline by annotation");130analyzer.shouldContain("java/lang/invoke/MethodHandle::invokeBasic (not loaded) not inlineable");131}132133static class TestIndy {134static String str = "";135136// @DontInline137static void test() {138String s1 = "" + str; // indy (linked)139140for (int i = 0; i < 200_000; i++) {} // trigger OSR compilation141142String s2 = "" + str; // indy (not linked)143}144145public static void main(String[] args) {146test();147}148}149150/* ======================================================================== */151152public static void main(String[] args) throws IOException {153testStatic();154testStaticInit();155testIndy();156}157}158159160