hotspot/test/runtime/CommandLine/PrintTouchedMethods.java
author tschatzl
Wed, 19 Aug 2015 13:47:40 +0200
changeset 32377 5ee15c417d02
parent 32074 54b9558a71a2
child 36851 03e2f4d0a421
permissions -rw-r--r--
8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure Summary: Remember for every generation whether the memory for that generation has already been exhausted. If so, do not try to get a new region for these generations. Further, if the last generation is full, early exit from copy_to_survivor_space. Reviewed-by: jmasa, brutisso
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
/*
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    27
 * @modules java.base/sun.misc
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    28
 *          java.management
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    29
 * @library /testlibrary
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;
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    36
import jdk.test.lib.*;
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    37
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    38
public class PrintTouchedMethods {
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 static void main(String args[]) throws Exception {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    41
      String[] javaArgs1 = {"-XX:-UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    42
      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(javaArgs1);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    43
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    44
      // UnlockDiagnostic turned off, should fail
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    45
      OutputAnalyzer output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    46
      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
    47
      output.shouldContain("Error: Could not create the Java Virtual Machine.");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    48
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    49
      String[] javaArgs2 = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    50
      pb = ProcessTools.createJavaProcessBuilder(javaArgs2);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    51
      output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    52
      // check order:
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    53
      // 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
    54
      // 2 should contain TestLogMethods.methodA:()V
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    55
      // 3 should not contain TestLogMethods.methodB:()V
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    56
      // Repeat above for another run with -Xint
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    57
      List<String> lines = output.asLines();
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    58
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    59
      if (lines.size() < 1) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    60
        throw new Exception("Empty output");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    61
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    62
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    63
      String first = lines.get(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    64
      if (!first.equals("# Method::print_touched_methods version 1")) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    65
        throw new Exception("First line mismatch");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    66
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    67
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    68
      output.shouldContain("TestLogTouchedMethods.methodA:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    69
      output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    70
      output.shouldHaveExitValue(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    71
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    72
      String[] javaArgs3 = {"-XX:+UnlockDiagnosticVMOptions", "-Xint", "-XX:+LogTouchedMethods", "-XX:+PrintTouchedMethodsAtExit", "TestLogTouchedMethods"};
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    73
      pb = ProcessTools.createJavaProcessBuilder(javaArgs3);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    74
      output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    75
      lines = output.asLines();
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    76
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    77
      if (lines.size() < 1) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    78
        throw new Exception("Empty output");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    79
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    80
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    81
      first = lines.get(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    82
      if (!first.equals("# Method::print_touched_methods version 1")) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    83
        throw new Exception("First line mismatch");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    84
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    85
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    86
      output.shouldContain("TestLogTouchedMethods.methodA:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    87
      output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    88
      output.shouldHaveExitValue(0);
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
    89
32074
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    90
      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
    91
      pb = ProcessTools.createJavaProcessBuilder(javaArgs4);
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    92
      output = new OutputAnalyzer(pb.start());
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    93
      lines = output.asLines();
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    94
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    95
      if (lines.size() < 1) {
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    96
        throw new Exception("Empty output");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    97
      }
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    98
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
    99
      first = lines.get(0);
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   100
      if (!first.equals("# Method::print_touched_methods version 1")) {
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   101
        throw new Exception("First line mismatch");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   102
      }
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   103
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   104
      output.shouldContain("TestLogTouchedMethods.methodA:()V");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   105
      output.shouldNotContain("TestLogTouchedMethods.methodB:()V");
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   106
      output.shouldHaveExitValue(0);
54b9558a71a2 8132242: LogTouchedMethods (8025692) asserts if TieredCompilation is off.
minqi
parents: 31790
diff changeset
   107
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   108
      // Test jcmd PrintTouchedMethods VM.print_touched_methods
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   109
      String pid = Integer.toString(ProcessTools.getProcessId());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   110
      pb = new ProcessBuilder();
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   111
      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
   112
      output = new OutputAnalyzer(pb.start());
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   113
      try {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   114
        output.shouldContain("PrintTouchedMethods.main:([Ljava/lang/String;)V");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   115
      } catch (RuntimeException e) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   116
        output.shouldContain("Unknown diagnostic command");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   117
      }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   118
  }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents:
diff changeset
   119
}