Path: blob/master/test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java
40942 views
/*1* Copyright (c) 2015, 2016, 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 802569226* @modules java.base/jdk.internal.misc27* java.management28* @library /test/lib29* @compile TestLogTouchedMethods.java PrintTouchedMethods.java30* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+LogTouchedMethods 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",46"TestLogTouchedMethods");4748// UnlockDiagnostic turned off, should fail49OutputAnalyzer output = new OutputAnalyzer(pb.start());50output.shouldContain("Error: VM option 'LogTouchedMethods' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");51output.shouldContain("Error: Could not create the Java Virtual Machine.");5253pb = ProcessTools.createJavaProcessBuilder(54"-XX:+UnlockDiagnosticVMOptions",55"-XX:+LogTouchedMethods",56"-XX:+PrintTouchedMethodsAtExit",57"TestLogTouchedMethods");58output = new OutputAnalyzer(pb.start());59// check order:60// 1 "# Method::print_touched_methods version 1" is the first in first line61// 2 should contain TestLogMethods.methodA:()V62// 3 should not contain TestLogMethods.methodB:()V63// Repeat above for another run with -Xint64List<String> lines = output.asLines();6566if (lines.size() < 1) {67throw new Exception("Empty output");68}6970String first = lines.get(0);71if (!first.equals("# Method::print_touched_methods version 1")) {72throw new Exception("First line mismatch");73}7475output.shouldContain("TestLogTouchedMethods.methodA:()V");76output.shouldNotContain("TestLogTouchedMethods.methodB:()V");77output.shouldHaveExitValue(0);7879pb = ProcessTools.createJavaProcessBuilder(80"-XX:+UnlockDiagnosticVMOptions",81"-Xint",82"-XX:+LogTouchedMethods",83"-XX:+PrintTouchedMethodsAtExit",84"TestLogTouchedMethods");85output = new OutputAnalyzer(pb.start());86lines = output.asLines();8788if (lines.size() < 1) {89throw new Exception("Empty output");90}9192first = lines.get(0);93if (!first.equals("# Method::print_touched_methods version 1")) {94throw new Exception("First line mismatch");95}9697output.shouldContain("TestLogTouchedMethods.methodA:()V");98output.shouldNotContain("TestLogTouchedMethods.methodB:()V");99output.shouldHaveExitValue(0);100101pb = ProcessTools.createJavaProcessBuilder(102"-XX:+UnlockDiagnosticVMOptions",103"-Xint",104"-XX:+LogTouchedMethods",105"-XX:+PrintTouchedMethodsAtExit",106"-XX:-TieredCompilation",107"TestLogTouchedMethods");108output = new OutputAnalyzer(pb.start());109lines = output.asLines();110111if (lines.size() < 1) {112throw new Exception("Empty output");113}114115first = lines.get(0);116if (!first.equals("# Method::print_touched_methods version 1")) {117throw new Exception("First line mismatch");118}119120output.shouldContain("TestLogTouchedMethods.methodA:()V");121output.shouldNotContain("TestLogTouchedMethods.methodB:()V");122output.shouldHaveExitValue(0);123124// Test jcmd PrintTouchedMethods VM.print_touched_methods125String pid = Long.toString(ProcessTools.getProcessId());126pb = new ProcessBuilder();127pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.print_touched_methods"});128output = new OutputAnalyzer(pb.start());129try {130output.shouldContain("PrintTouchedMethods.main:([Ljava/lang/String;)V");131} catch (RuntimeException e) {132output.shouldContain("Unknown diagnostic command");133}134}135}136137138