hotspot/test/compiler/codecache/CheckSegmentedCodeCache.java
author amurillo
Mon, 11 Apr 2016 14:21:25 -0700
changeset 37297 d65d53a0ecc7
parent 36851 03e2f4d0a421
parent 37253 45e69c7b0bac
child 40059 c2304140ed64
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
     1
/*
37253
45e69c7b0bac 8152929: Remove UNSUPPORTED_GC_OPTION, use UNSUPPORTED_OPTION instead
pliden
parents: 33730
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
26796
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
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    24
import jdk.test.lib.*;
27418
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
    25
import sun.hotspot.WhiteBox;
26796
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
/*
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    28
 * @test CheckSegmentedCodeCache
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    29
 * @bug 8015774
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 30604
diff changeset
    30
 * @library /testlibrary /test/lib
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    31
 * @summary "Checks VM options related to the segmented code cache"
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 33730
diff changeset
    32
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
    33
 *          java.management
27418
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
    34
 * @build CheckSegmentedCodeCache
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
    35
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
    36
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
    37
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI CheckSegmentedCodeCache
26796
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
public class CheckSegmentedCodeCache {
27418
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
    40
  private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    41
  // Code heap names
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
    42
  private static final String NON_METHOD = "CodeHeap 'non-nmethods'";
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    43
  private static final String PROFILED = "CodeHeap 'profiled nmethods'";
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    44
  private static final String NON_PROFILED = "CodeHeap 'non-profiled nmethods'";
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    45
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    46
  private static void verifySegmentedCodeCache(ProcessBuilder pb, boolean enabled) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    47
    OutputAnalyzer out = new OutputAnalyzer(pb.start());
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
    48
    out.shouldHaveExitValue(0);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    49
    if (enabled) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    50
      try {
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
    51
        // 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
    52
        out.shouldContain(NON_METHOD);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    53
      } catch (RuntimeException e) {
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
    54
        // Check if TieredCompilation is disabled (in a client VM)
37253
45e69c7b0bac 8152929: Remove UNSUPPORTED_GC_OPTION, use UNSUPPORTED_OPTION instead
pliden
parents: 33730
diff changeset
    55
        if(!out.getOutput().contains("-XX:+TieredCompilation not supported in this VM")) {
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
    56
          // Code cache is not segmented
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
    57
          throw new RuntimeException("No code cache segmentation.");
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
    58
        }
26796
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
    } else {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    61
      out.shouldNotContain(NON_METHOD);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    62
    }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    63
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    64
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    65
  private static void verifyCodeHeapNotExists(ProcessBuilder pb, String... heapNames) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    66
    OutputAnalyzer out = new OutputAnalyzer(pb.start());
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
    67
    out.shouldHaveExitValue(0);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    68
    for (String name : heapNames) {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    69
      out.shouldNotContain(name);
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
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    72
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    73
  private static void failsWith(ProcessBuilder pb, String message) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    74
    OutputAnalyzer out = new OutputAnalyzer(pb.start());
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    75
    out.shouldContain(message);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    76
    out.shouldHaveExitValue(1);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    77
  }
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
  /**
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    80
   * Check the result of segmented code cache related VM options.
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    81
   */
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    82
  public static void main(String[] args) throws Exception {
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    83
    ProcessBuilder pb;
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    84
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    85
    // Disabled with ReservedCodeCacheSize < 240MB
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    86
    pb = ProcessTools.createJavaProcessBuilder("-XX:ReservedCodeCacheSize=239m",
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, false);
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
    // Disabled without TieredCompilation
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    91
    pb = ProcessTools.createJavaProcessBuilder("-XX:-TieredCompilation",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    92
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    93
    verifySegmentedCodeCache(pb, false);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    94
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    95
    // Enabled with TieredCompilation and ReservedCodeCacheSize >= 240MB
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    96
    pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    97
                                               "-XX:ReservedCodeCacheSize=240m",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    98
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
    99
    verifySegmentedCodeCache(pb, true);
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   100
    pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   101
                                               "-XX:ReservedCodeCacheSize=400m",
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   102
                                               "-XX:+PrintCodeCache", "-version");
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   103
    verifySegmentedCodeCache(pb, true);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   104
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   105
    // Always enabled if SegmentedCodeCache is set
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   106
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   107
                                               "-XX:-TieredCompilation",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   108
                                               "-XX:ReservedCodeCacheSize=239m",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   109
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   110
    verifySegmentedCodeCache(pb, true);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   111
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   112
    // The profiled and non-profiled code heaps should not be available in
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   113
    // interpreter-only mode
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   114
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   115
                                               "-Xint",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   116
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   117
    verifyCodeHeapNotExists(pb, PROFILED, NON_PROFILED);
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   118
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   119
    // If we stop compilation at CompLevel_none or CompLevel_simple we
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   120
    // don't need a profiled code heap.
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   121
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   122
                                               "-XX:TieredStopAtLevel=0",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   123
                                               "-XX:+PrintCodeCache", "-version");
27015
7a7b66fbc782 8059559: SIGSEGV at CodeHeap::allocate(unsigned int, bool)
thartmann
parents: 26919
diff changeset
   124
    verifyCodeHeapNotExists(pb, PROFILED);
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   125
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   126
                                               "-XX:TieredStopAtLevel=1",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   127
                                               "-XX:+PrintCodeCache", "-version");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   128
    verifyCodeHeapNotExists(pb, PROFILED);
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   129
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   130
    // Fails with too small non-nmethod code heap size
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   131
    pb = ProcessTools.createJavaProcessBuilder("-XX:NonNMethodCodeHeapSize=100K");
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   132
    failsWith(pb, "Invalid NonNMethodCodeHeapSize");
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   133
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   134
    // Fails if code heap sizes do not add up
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   135
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   136
                                               "-XX:ReservedCodeCacheSize=10M",
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   137
                                               "-XX:NonNMethodCodeHeapSize=5M",
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   138
                                               "-XX:ProfiledCodeHeapSize=5M",
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   139
                                               "-XX:NonProfiledCodeHeapSize=5M");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   140
    failsWith(pb, "Invalid code heap sizes");
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   141
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   142
    // Fails if not enough space for VM internal code
27418
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
   143
    long minUseSpace = WHITE_BOX.getUintxVMFlag("CodeCacheMinimumUseSpace");
27431
5f970b31939c 8062250: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java fails after CodeCacheMinimumFreeSpace removal
thartmann
parents: 27418
diff changeset
   144
    // minimum size: CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)
5f970b31939c 8062250: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java fails after CodeCacheMinimumFreeSpace removal
thartmann
parents: 27418
diff changeset
   145
    long minSize = (Platform.isDebugBuild() ? 3 : 1) * minUseSpace;
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   146
    pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
27418
a13fdcbaa345 8060479: [TESTBUG] compiler/codecache/CheckSegmentedCodeCache.java test fails with product build
thartmann
parents: 27015
diff changeset
   147
                                               "-XX:ReservedCodeCacheSize=" + minSize,
26796
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   148
                                               "-XX:InitialCodeCacheSize=100K");
26919
361b4b4c92c0 8059468: Fix PrintCodeCache output changed by JDK-8059137
thartmann
parents: 26796
diff changeset
   149
    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
   150
  }
666464578742 8015774: Add support for multiple code heaps
thartmann
parents:
diff changeset
   151
}