Path: blob/master/test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java
64474 views
/*1* Copyright (c) 2015, 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 8025692 827333326* @requires vm.flavor != "zero"27* @modules java.base/jdk.internal.misc28* java.management29* @library /test/lib30* @run driver PrintTouchedMethods31*/3233import java.io.File;34import java.util.List;35import jdk.test.lib.process.ProcessTools;36import jdk.test.lib.process.OutputAnalyzer;37import jdk.test.lib.JDKToolFinder;3839public class PrintTouchedMethods {4041public static void main(String args[]) throws Exception {42ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(43"-XX:-UnlockDiagnosticVMOptions",44"-XX:+LogTouchedMethods",45"-XX:+PrintTouchedMethodsAtExit",46TestLogTouchedMethods.class.getName());4748// UnlockDiagnostic turned off, should fail49OutputAnalyzer output = new OutputAnalyzer(pb.start());50output.shouldNotHaveExitValue(0);51output.shouldContain("Error: VM option 'LogTouchedMethods' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");52output.shouldContain("Error: Could not create the Java Virtual Machine.");5354pb = ProcessTools.createJavaProcessBuilder(55"-XX:+UnlockDiagnosticVMOptions",56"-XX:+LogTouchedMethods",57"-XX:+PrintTouchedMethodsAtExit",58TestLogTouchedMethods.class.getName());59output = new OutputAnalyzer(pb.start());60// check order:61// 1 "# Method::print_touched_methods version 1" is the first in first line62// 2 should contain TestLogMethods.methodA:()V63// 3 should not contain TestLogMethods.methodB:()V64// Repeat above for another run with -Xint65List<String> lines = output.asLines();6667if (lines.size() < 1) {68throw new Exception("Empty output");69}7071String first = lines.get(0);72if (!first.equals("# Method::print_touched_methods version 1")) {73throw new Exception("First line mismatch");74}7576output.shouldContain("TestLogTouchedMethods.methodA:()V");77output.shouldNotContain("TestLogTouchedMethods.methodB:()V");78output.shouldHaveExitValue(0);7980pb = ProcessTools.createJavaProcessBuilder(81"-XX:+UnlockDiagnosticVMOptions",82"-Xint",83"-XX:+LogTouchedMethods",84"-XX:+PrintTouchedMethodsAtExit",85TestLogTouchedMethods.class.getName());86output = new OutputAnalyzer(pb.start());87lines = output.asLines();8889if (lines.size() < 1) {90throw new Exception("Empty output");91}9293first = lines.get(0);94if (!first.equals("# Method::print_touched_methods version 1")) {95throw new Exception("First line mismatch");96}9798output.shouldContain("TestLogTouchedMethods.methodA:()V");99output.shouldNotContain("TestLogTouchedMethods.methodB:()V");100output.shouldHaveExitValue(0);101102pb = ProcessTools.createJavaProcessBuilder(103"-XX:+UnlockDiagnosticVMOptions",104"-Xint",105"-XX:+LogTouchedMethods",106"-XX:+PrintTouchedMethodsAtExit",107"-XX:-TieredCompilation",108TestLogTouchedMethods.class.getName());109output = new OutputAnalyzer(pb.start());110lines = output.asLines();111112if (lines.size() < 1) {113throw new Exception("Empty output");114}115116first = lines.get(0);117if (!first.equals("# Method::print_touched_methods version 1")) {118throw new Exception("First line mismatch");119}120121output.shouldContain("TestLogTouchedMethods.methodA:()V");122output.shouldNotContain("TestLogTouchedMethods.methodB:()V");123output.shouldHaveExitValue(0);124}125}126127128