hotspot/test/compiler/codecache/CheckSegmentedCodeCache.java
author thartmann
Tue, 30 Sep 2014 15:44:43 +0200
changeset 26919 361b4b4c92c0
parent 26796 666464578742
child 27015 7a7b66fbc782
permissions -rw-r--r--
8059468: Fix PrintCodeCache output changed by JDK-8059137 Summary: Change output of PrintCodeCache to print "CodeCache" instead of "Code Cache" and change name of non-method code heap to non-nmethod code heap. Reviewed-by: vlivanov, anoll
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     1
/*
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     4
 *
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     7
 * published by the Free Software Foundation.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     8
 *
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    13
 * accompanied this code).
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    14
 *
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    18
 *
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    21
 * questions.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    22
 */
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    23
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    24
import com.oracle.java.testlibrary.*;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    25
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    26
/*
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    27
 * @test CheckSegmentedCodeCache
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    28
 * @bug 8015774
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    29
 * @summary "Checks VM options related to the segmented code cache"
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    30
 * @library /testlibrary
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    31
 * @run main/othervm CheckSegmentedCodeCache
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    32
 */
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    33
public class CheckSegmentedCodeCache {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    34
  // Code heap names
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
    35
  private static final String NON_METHOD = "CodeHeap 'non-nmethods'";
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    36
  private static final String PROFILED = "CodeHeap 'profiled nmethods'";
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    37
  private static final String NON_PROFILED = "CodeHeap 'non-profiled nmethods'";
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    38
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    39
  private static void verifySegmentedCodeCache(ProcessBuilder pb, boolean enabled) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    40
    OutputAnalyzer out = new OutputAnalyzer(pb.start());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    41
    if (enabled) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    42
      try {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
    43
        // Non-nmethod code heap should be always available with the segmented code cache
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    44
        out.shouldContain(NON_METHOD);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    45
      } catch (RuntimeException e) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    46
        // TieredCompilation is disabled in a client VM
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    47
        out.shouldContain("TieredCompilation is disabled in this release.");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    48
      }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    49
    } else {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    50
      out.shouldNotContain(NON_METHOD);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    51
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    52
    out.shouldHaveExitValue(0);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    53
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    54
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    55
  private static void verifyCodeHeapNotExists(ProcessBuilder pb, String... heapNames) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    56
    OutputAnalyzer out = new OutputAnalyzer(pb.start());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    57
    for (String name : heapNames) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    58
      out.shouldNotContain(name);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    59
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    60
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    61
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    62
  private static void failsWith(ProcessBuilder pb, String message) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    63
    OutputAnalyzer out = new OutputAnalyzer(pb.start());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    64
    out.shouldContain(message);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    65
    out.shouldHaveExitValue(1);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    66
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    67
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    68
  /**
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    69
   * Check the result of segmented code cache related VM options.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    70
   */
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    71
  public static void main(String[] args) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    72
    ProcessBuilder pb;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    73
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    74
    // Disabled with ReservedCodeCacheSize < 240MB
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    75
    pb = ProcessTools.createJavaProcessBuilder("-XX:ReservedCodeCacheSize=239m",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    76
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    77
    verifySegmentedCodeCache(pb, false);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    78
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    79
    // Disabled without TieredCompilation
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    80
    pb = ProcessTools.createJavaProcessBuilder("-XX:-TieredCompilation",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    81
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    82
    verifySegmentedCodeCache(pb, false);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    83
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    84
    // Enabled with TieredCompilation and ReservedCodeCacheSize >= 240MB
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    85
    pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    86
                                               "-XX:ReservedCodeCacheSize=240m",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    87
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    88
    verifySegmentedCodeCache(pb, true);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    89
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    90
    // Always enabled if SegmentedCodeCache is set
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    91
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    92
                                               "-XX:-TieredCompilation",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    93
                                               "-XX:ReservedCodeCacheSize=239m",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    94
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    95
    verifySegmentedCodeCache(pb, true);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    96
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    97
    // The profiled and non-profiled code heaps should not be available in
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    98
    // interpreter-only mode
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    99
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   100
                                               "-Xint",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   101
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   102
    verifyCodeHeapNotExists(pb, PROFILED, NON_PROFILED);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   103
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   104
                                               "-XX:TieredStopAtLevel=0",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   105
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   106
    verifyCodeHeapNotExists(pb, PROFILED, NON_PROFILED);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   107
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   108
    // If we stop compilation at CompLevel_simple
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   109
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   110
                                               "-XX:TieredStopAtLevel=1",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   111
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   112
    verifyCodeHeapNotExists(pb, PROFILED);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   113
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   114
    // Fails with too small non-nmethod code heap size
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   115
    pb = ProcessTools.createJavaProcessBuilder("-XX:NonNMethodCodeHeapSize=100K");
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   116
    failsWith(pb, "Invalid NonNMethodCodeHeapSize");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   117
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   118
    // Fails if code heap sizes do not add up
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   119
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   120
                                               "-XX:ReservedCodeCacheSize=10M",
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   121
                                               "-XX:NonNMethodCodeHeapSize=5M",
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   122
                                               "-XX:ProfiledCodeHeapSize=5M",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   123
                                               "-XX:NonProfiledCodeHeapSize=5M");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   124
    failsWith(pb, "Invalid code heap sizes");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   125
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   126
    // Fails if not enough space for VM internal code
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   127
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   128
                                               "-XX:ReservedCodeCacheSize=1700K",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   129
                                               "-XX:InitialCodeCacheSize=100K");
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   130
    failsWith(pb, "Not enough space in non-nmethod code heap to run VM");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   131
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   132
}