test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java
changeset 47216 71c04702a3d5
parent 40631 ed82623d7831
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    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  * @test
       
    26  * @bug 8025692
       
    27  * @modules java.base/jdk.internal.misc
       
    28  *          java.management
       
    29  * @library /test/lib
       
    30  * @compile TestLogTouchedMethods.java PrintTouchedMethods.java
       
    31  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+LogTouchedMethods PrintTouchedMethods
       
    32  */
       
    33 
       
    34 import java.io.File;
       
    35 import java.util.List;
       
    36 import jdk.test.lib.process.ProcessTools;
       
    37 import jdk.test.lib.process.OutputAnalyzer;
       
    38 import jdk.test.lib.JDKToolFinder;
       
    39 
       
    40 public class PrintTouchedMethods {
       
    41 
       
    42     public static void main(String args[]) throws Exception {
       
    43       String[] javaArgs1 = {"-XX:-UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
       
    44       ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(javaArgs1);
       
    45 
       
    46       // UnlockDiagnostic turned off, should fail
       
    47       OutputAnalyzer output = new OutputAnalyzer(pb.start());
       
    48       output.shouldContain("Error: VM option 'LogTouchedMethods' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
       
    49       output.shouldContain("Error: Could not create the Java Virtual Machine.");
       
    50 
       
    51       String[] javaArgs2 = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
       
    52       pb = ProcessTools.createJavaProcessBuilder(javaArgs2);
       
    53       output = new OutputAnalyzer(pb.start());
       
    54       // check order:
       
    55       // 1 "# Method::print_touched_methods version 1" is the first in first line
       
    56       // 2 should contain TestLogMethods.methodA:()V
       
    57       // 3 should not contain TestLogMethods.methodB:()V
       
    58       // Repeat above for another run with -Xint
       
    59       List<String> lines = output.asLines();
       
    60 
       
    61       if (lines.size() < 1) {
       
    62         throw new Exception("Empty output");
       
    63       }
       
    64 
       
    65       String first = lines.get(0);
       
    66       if (!first.equals("# Method::print_touched_methods version 1")) {
       
    67         throw new Exception("First line mismatch");
       
    68       }
       
    69 
       
    70       output.shouldContain("TestLogTouchedMethods.methodA:()V");
       
    71       output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
       
    72       output.shouldHaveExitValue(0);
       
    73 
       
    74       String[] javaArgs3 = {"-XX:+UnlockDiagnosticVMOptions", "-Xint", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
       
    75       pb = ProcessTools.createJavaProcessBuilder(javaArgs3);
       
    76       output = new OutputAnalyzer(pb.start());
       
    77       lines = output.asLines();
       
    78 
       
    79       if (lines.size() < 1) {
       
    80         throw new Exception("Empty output");
       
    81       }
       
    82 
       
    83       first = lines.get(0);
       
    84       if (!first.equals("# Method::print_touched_methods version 1")) {
       
    85         throw new Exception("First line mismatch");
       
    86       }
       
    87 
       
    88       output.shouldContain("TestLogTouchedMethods.methodA:()V");
       
    89       output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
       
    90       output.shouldHaveExitValue(0);
       
    91 
       
    92       String[] javaArgs4 = {"-XX:+UnlockDiagnosticVMOptions", "-Xint", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "-XX:-TieredCompilation", "TestLogTouchedMethods"};
       
    93       pb = ProcessTools.createJavaProcessBuilder(javaArgs4);
       
    94       output = new OutputAnalyzer(pb.start());
       
    95       lines = output.asLines();
       
    96 
       
    97       if (lines.size() < 1) {
       
    98         throw new Exception("Empty output");
       
    99       }
       
   100 
       
   101       first = lines.get(0);
       
   102       if (!first.equals("# Method::print_touched_methods version 1")) {
       
   103         throw new Exception("First line mismatch");
       
   104       }
       
   105 
       
   106       output.shouldContain("TestLogTouchedMethods.methodA:()V");
       
   107       output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
       
   108       output.shouldHaveExitValue(0);
       
   109 
       
   110       // Test jcmd PrintTouchedMethods VM.print_touched_methods
       
   111       String pid = Long.toString(ProcessTools.getProcessId());
       
   112       pb = new ProcessBuilder();
       
   113       pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.print_touched_methods"});
       
   114       output = new OutputAnalyzer(pb.start());
       
   115       try {
       
   116         output.shouldContain("PrintTouchedMethods.main:([Ljava/lang/String;)V");
       
   117       } catch (RuntimeException e) {
       
   118         output.shouldContain("Unknown diagnostic command");
       
   119       }
       
   120   }
       
   121 }