test/hotspot/jtreg/runtime/CommandLine/PrintTouchedMethods.java
author epavlova
Thu, 20 Jun 2019 11:42:33 -0700
changeset 55455 76647c08ce0c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225684: [AOT] vmTestbase/vm/oom/production/AlwaysOOMProduction tests fail with AOTed java.base Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38089
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     4
 *
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     8
 *
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    13
 * accompanied this code).
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    14
 *
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    18
 *
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    21
 * questions.
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    22
 */
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    23
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    24
/*
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    25
 * @test
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    26
 * @bug 8025692
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 32074
diff changeset
    27
 * @modules java.base/jdk.internal.misc
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    28
 *          java.management
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38089
diff changeset
    29
 * @library /test/lib
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    30
 * @compile TestLogTouchedMethods.java PrintTouchedMethods.java
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    31
 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+LogTouchedMethods PrintTouchedMethods
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    32
 */
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    33
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    34
import java.io.File;
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    35
import java.util.List;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38089
diff changeset
    36
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38089
diff changeset
    37
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38089
diff changeset
    38
import jdk.test.lib.JDKToolFinder;
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    39
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    40
public class PrintTouchedMethods {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    41
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    42
    public static void main(String args[]) throws Exception {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    43
      String[] javaArgs1 = {"-XX:-UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    44
      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(javaArgs1);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    45
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    46
      // UnlockDiagnostic turned off, should fail
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    47
      OutputAnalyzer output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    48
      output.shouldContain("Error: VM option 'LogTouchedMethods' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    49
      output.shouldContain("Error: Could not create the Java Virtual Machine.");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    50
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    51
      String[] javaArgs2 = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    52
      pb = ProcessTools.createJavaProcessBuilder(javaArgs2);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    53
      output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    54
      // check order:
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    55
      // 1 "# Method::print_touched_methods version 1" is the first in first line
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    56
      // 2 should contain TestLogMethods.methodA:()V
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    57
      // 3 should not contain TestLogMethods.methodB:()V
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    58
      // Repeat above for another run with -Xint
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    59
      List<String> lines = output.asLines();
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    60
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    61
      if (lines.size() < 1) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    62
        throw new Exception("Empty output");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    63
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    64
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    65
      String first = lines.get(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    66
      if (!first.equals("# Method::print_touched_methods version 1")) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    67
        throw new Exception("First line mismatch");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    68
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    69
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    70
      output.shouldContain("TestLogTouchedMethods.methodA:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    71
      output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    72
      output.shouldHaveExitValue(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    73
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    74
      String[] javaArgs3 = {"-XX:+UnlockDiagnosticVMOptions", "-Xint", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    75
      pb = ProcessTools.createJavaProcessBuilder(javaArgs3);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    76
      output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    77
      lines = output.asLines();
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    78
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    79
      if (lines.size() < 1) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    80
        throw new Exception("Empty output");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    81
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    82
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    83
      first = lines.get(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    84
      if (!first.equals("# Method::print_touched_methods version 1")) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    85
        throw new Exception("First line mismatch");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    86
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    87
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    88
      output.shouldContain("TestLogTouchedMethods.methodA:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    89
      output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    90
      output.shouldHaveExitValue(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    91
32074
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    92
      String[] javaArgs4 = {"-XX:+UnlockDiagnosticVMOptions", "-Xint", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "-XX:-TieredCompilation", "TestLogTouchedMethods"};
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    93
      pb = ProcessTools.createJavaProcessBuilder(javaArgs4);
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    94
      output = new OutputAnalyzer(pb.start());
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    95
      lines = output.asLines();
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    96
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    97
      if (lines.size() < 1) {
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    98
        throw new Exception("Empty output");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    99
      }
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   100
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   101
      first = lines.get(0);
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   102
      if (!first.equals("# Method::print_touched_methods version 1")) {
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   103
        throw new Exception("First line mismatch");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   104
      }
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   105
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   106
      output.shouldContain("TestLogTouchedMethods.methodA:()V");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   107
      output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   108
      output.shouldHaveExitValue(0);
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   109
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   110
      // Test jcmd PrintTouchedMethods VM.print_touched_methods
38089
9e58203ef0e2 8153992: Some hotspot tests fail on compact2 due to an unnecessary test library dependency
akulyakh
parents: 36851
diff changeset
   111
      String pid = Long.toString(ProcessTools.getProcessId());
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   112
      pb = new ProcessBuilder();
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   113
      pb.command(new String[] {JDKToolFinder.getJDKTool("jcmd"), pid, "VM.print_touched_methods"});
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   114
      output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   115
      try {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   116
        output.shouldContain("PrintTouchedMethods.main:([Ljava/lang/String;)V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   117
      } catch (RuntimeException e) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   118
        output.shouldContain("Unknown diagnostic command");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   119
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   120
  }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   121
}