< prev index next >

test/hotspot/jtreg/compiler/sharedstubs/SharedTrampolineTest.java

Print this page

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 /**
 26  * @test SharedTrampolineTest id=C2
 27  * @summary Checks that trampolines can be shared for static method.
 28  * @bug 8280152
 29  * @library /test/lib
 30  *

 31  * @requires vm.opt.TieredCompilation == null
 32  * @requires os.arch=="aarch64" | os.arch=="riscv64"
 33  * @requires vm.debug
 34  *
 35  * @run driver compiler.sharedstubs.SharedTrampolineTest -XX:-TieredCompilation
 36  */
 37 
 38 package compiler.sharedstubs;
 39 
 40 import java.util.ArrayList;
 41 import java.util.List;
 42 import java.util.regex.Pattern;
 43 import jdk.test.lib.process.OutputAnalyzer;
 44 import jdk.test.lib.process.ProcessTools;
 45 
 46 public class SharedTrampolineTest {
 47     private final static int ITERATIONS_TO_HEAT_LOOP = 20_000;
 48 
 49     private static void runTest(String test) throws Exception {
 50         String testClassName = SharedTrampolineTest.class.getName() + "$" + test;
 51         ArrayList<String> command = new ArrayList<String>();

 52         command.add("-XX:+UnlockDiagnosticVMOptions");
 53         command.add("-Xbatch");
 54         command.add("-XX:+PrintRelocations");
 55         command.add("-XX:CompileCommand=compileonly," + testClassName + "::" + "test");
 56         command.add("-XX:CompileCommand=dontinline," + testClassName + "::" + "test");
 57         command.add("-XX:CompileCommand=dontinline," + testClassName + "::" + "log");
 58         command.add(testClassName);
 59         command.add("a");
 60 
 61         ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(command);
 62 
 63         OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
 64 
 65         analyzer.shouldHaveExitValue(0);
 66 
 67         System.out.println(analyzer.getOutput());
 68 
 69         checkOutput(analyzer);
 70     }
 71 
 72     public static void main(String[] args) throws Exception {
 73         String[] tests = new String[] {"StaticMethodTest"};
 74         for (String test : tests) {
 75             runTest(test);
 76         }
 77     }
 78 
 79     private static void checkOutput(OutputAnalyzer output) {
 80         List<String> addrs = Pattern.compile("\\(trampoline_stub\\) addr=(\\w+) .*\\[trampoline owner")
 81             .matcher(output.getStdout())
 82             .results()
 83             .map(m -> m.group(1))
 84             .toList();
 85         if (addrs.stream().distinct().count() >= addrs.size()) {
 86             throw new RuntimeException("No runtime trampoline stubs reused: distinct " + addrs.stream().distinct().count() + ", in total " + addrs.size());
 87         }
 88     }
 89 
 90     public static class StaticMethodTest {
 91         private static void log(int i, String msg) {
 92         }
 93 
 94         static void test(int i, String[] args) {
 95             if (i % args.length == 0) {

 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 /**
 26  * @test SharedTrampolineTest id=C2
 27  * @summary Checks that trampolines can be shared for static method.
 28  * @bug 8280152
 29  * @library /test/lib
 30  *
 31  * @requires vm.compiler2.enabled
 32  * @requires vm.opt.TieredCompilation == null
 33  * @requires os.arch=="aarch64" | os.arch=="riscv64"
 34  * @requires vm.debug
 35  *
 36  * @run driver compiler.sharedstubs.SharedTrampolineTest -XX:-TieredCompilation
 37  */
 38 
 39 package compiler.sharedstubs;
 40 
 41 import java.util.ArrayList;
 42 import java.util.List;
 43 import java.util.regex.Pattern;
 44 import jdk.test.lib.process.OutputAnalyzer;
 45 import jdk.test.lib.process.ProcessTools;
 46 
 47 public class SharedTrampolineTest {
 48     private final static int ITERATIONS_TO_HEAT_LOOP = 20_000;
 49 
 50     private static void runTest(String compiler, String test) throws Exception {
 51         String testClassName = SharedTrampolineTest.class.getName() + "$" + test;
 52         ArrayList<String> command = new ArrayList<String>();
 53         command.add(compiler);
 54         command.add("-XX:+UnlockDiagnosticVMOptions");
 55         command.add("-Xbatch");
 56         command.add("-XX:+PrintRelocations");
 57         command.add("-XX:CompileCommand=compileonly," + testClassName + "::" + "test");
 58         command.add("-XX:CompileCommand=dontinline," + testClassName + "::" + "test");
 59         command.add("-XX:CompileCommand=dontinline," + testClassName + "::" + "log");
 60         command.add(testClassName);
 61         command.add("a");
 62 
 63         ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(command);
 64 
 65         OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
 66 
 67         analyzer.shouldHaveExitValue(0);
 68 
 69         System.out.println(analyzer.getOutput());
 70 
 71         checkOutput(analyzer);
 72     }
 73 
 74     public static void main(String[] args) throws Exception {
 75         String[] tests = new String[] {"StaticMethodTest"};
 76         for (String test : tests) {
 77             runTest(args[0], test);
 78         }
 79     }
 80 
 81     private static void checkOutput(OutputAnalyzer output) {
 82         List<String> addrs = Pattern.compile("\\(trampoline_stub\\) addr=(\\w+) .*\\[trampoline owner")
 83             .matcher(output.getStdout())
 84             .results()
 85             .map(m -> m.group(1))
 86             .toList();
 87         if (addrs.stream().distinct().count() >= addrs.size()) {
 88             throw new RuntimeException("No runtime trampoline stubs reused: distinct " + addrs.stream().distinct().count() + ", in total " + addrs.size());
 89         }
 90     }
 91 
 92     public static class StaticMethodTest {
 93         private static void log(int i, String msg) {
 94         }
 95 
 96         static void test(int i, String[] args) {
 97             if (i % args.length == 0) {
< prev index next >