Path: blob/master/test/hotspot/jtreg/compiler/inlining/PrintInlining.java
41152 views
/*1* Copyright (c) 2020, 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* @bug 825574226* @summary PrintInlining as compiler directive doesn't print virtual calls27* @modules java.base/jdk.internal.misc28* @library /test/lib29* @requires vm.flagless30*31* @run driver compiler.inlining.PrintInlining32*/3334package compiler.inlining;3536import jdk.test.lib.process.OutputAnalyzer;37import jdk.test.lib.process.ProcessTools;3839public class PrintInlining {4041static void test(String option) throws Exception {42ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(43"-XX:+IgnoreUnrecognizedVMOptions", "-showversion",44"-server", "-XX:-TieredCompilation", "-Xbatch", "-XX:-UseOnStackReplacement",45"-XX:CompileCommand=dontinline,*::bar",46"-XX:CompileCommand=compileonly,*::foo",47"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", option,48Launcher.class.getName());4950OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());5152analyzer.shouldHaveExitValue(0);5354// The test is applicable only to C2 (present in Server VM).55if (analyzer.getStderr().contains("Server VM")) {56analyzer.outputTo(System.out);57if (analyzer.asLines().stream()58.filter(s -> s.matches(".*A::bar.+virtual call.*"))59.count() != 1) {60throw new Exception("'" + option + "' didn't print virtual call.");61}62}63}6465public static void main(String[] args) throws Exception {66test("-XX:+PrintInlining");67test("-XX:CompileCommand=option,*::foo,PrintInlining");68}6970static class A {71void bar() {}72}7374static class B extends A {75void bar() {}76}7778static class C extends A {79void bar() {}80}8182static class D extends A {83void bar() {}84}8586static void foo(A a) {87a.bar();88}8990static class Launcher {91public static void main(String[] args) throws Exception {92A[] as = { new B(), new C(), new D() };93for (int i = 0; i < 20_000; i++) {94foo(as[i % 3]);95}96}97}98}99100101