Merge

Sat, 05 Oct 2013 08:01:36 -0700

author
stefank
date
Sat, 05 Oct 2013 08:01:36 -0700
changeset 5858
8618e0d7735b
parent 5856
087f02e22fc2
parent 5857
263f2c796d6c
child 5859
04b18a42c2f3

Merge

     1.1 --- a/src/os/linux/vm/globals_linux.hpp	Fri Oct 04 22:08:37 2013 +0200
     1.2 +++ b/src/os/linux/vm/globals_linux.hpp	Sat Oct 05 08:01:36 2013 -0700
     1.3 @@ -53,7 +53,7 @@
     1.4  // Defines Linux-specific default values. The flags are available on all
     1.5  // platforms, but they may have different default values on other platforms.
     1.6  //
     1.7 -define_pd_global(bool, UseLargePages, true);
     1.8 +define_pd_global(bool, UseLargePages, false);
     1.9  define_pd_global(bool, UseLargePagesIndividualAllocation, false);
    1.10  define_pd_global(bool, UseOSErrorReporting, false);
    1.11  define_pd_global(bool, UseThreadPriorities, true) ;
     2.1 --- a/src/os/linux/vm/os_linux.cpp	Fri Oct 04 22:08:37 2013 +0200
     2.2 +++ b/src/os/linux/vm/os_linux.cpp	Sat Oct 05 08:01:36 2013 -0700
     2.3 @@ -3361,13 +3361,15 @@
     2.4    if (FLAG_IS_DEFAULT(UseHugeTLBFS) &&
     2.5        FLAG_IS_DEFAULT(UseSHM) &&
     2.6        FLAG_IS_DEFAULT(UseTransparentHugePages)) {
     2.7 -    // If UseLargePages is specified on the command line try all methods,
     2.8 -    // if it's default, then try only UseTransparentHugePages.
     2.9 -    if (FLAG_IS_DEFAULT(UseLargePages)) {
    2.10 -      UseTransparentHugePages = true;
    2.11 -    } else {
    2.12 -      UseHugeTLBFS = UseTransparentHugePages = UseSHM = true;
    2.13 -    }
    2.14 +
    2.15 +    // The type of large pages has not been specified by the user.
    2.16 +
    2.17 +    // Try UseHugeTLBFS and then UseSHM.
    2.18 +    UseHugeTLBFS = UseSHM = true;
    2.19 +
    2.20 +    // Don't try UseTransparentHugePages since there are known
    2.21 +    // performance issues with it turned on. This might change in the future.
    2.22 +    UseTransparentHugePages = false;
    2.23    }
    2.24  
    2.25    if (UseTransparentHugePages) {
    2.26 @@ -3393,9 +3395,19 @@
    2.27  }
    2.28  
    2.29  void os::large_page_init() {
    2.30 -  if (!UseLargePages) {
    2.31 +  if (!UseLargePages &&
    2.32 +      !UseTransparentHugePages &&
    2.33 +      !UseHugeTLBFS &&
    2.34 +      !UseSHM) {
    2.35 +    // Not using large pages.
    2.36 +    return;
    2.37 +  }
    2.38 +
    2.39 +  if (!FLAG_IS_DEFAULT(UseLargePages) && !UseLargePages) {
    2.40 +    // The user explicitly turned off large pages.
    2.41 +    // Ignore the rest of the large pages flags.
    2.42 +    UseTransparentHugePages = false;
    2.43      UseHugeTLBFS = false;
    2.44 -    UseTransparentHugePages = false;
    2.45      UseSHM = false;
    2.46      return;
    2.47    }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/runtime/memory/LargePages/TestLargePagesFlags.java	Sat Oct 05 08:01:36 2013 -0700
     3.3 @@ -0,0 +1,389 @@
     3.4 +/*
     3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/* @test TestLargePagesFlags
    3.28 + * @summary Tests how large pages are choosen depending on the given large pages flag combinations.
    3.29 + * @library /testlibrary
    3.30 + * @run main TestLargePagesFlags
    3.31 + */
    3.32 +
    3.33 +import com.oracle.java.testlibrary.OutputAnalyzer;
    3.34 +import com.oracle.java.testlibrary.Platform;
    3.35 +import com.oracle.java.testlibrary.ProcessTools;
    3.36 +import java.util.ArrayList;
    3.37 +
    3.38 +public class TestLargePagesFlags {
    3.39 +
    3.40 +  public static void main(String [] args) throws Exception {
    3.41 +    if (!Platform.isLinux()) {
    3.42 +      System.out.println("Skipping. TestLargePagesFlags has only been implemented for Linux.");
    3.43 +      return;
    3.44 +    }
    3.45 +
    3.46 +    testUseTransparentHugePages();
    3.47 +    testUseHugeTLBFS();
    3.48 +    testUseSHM();
    3.49 +    testCombinations();
    3.50 +  }
    3.51 +
    3.52 +  public static void testUseTransparentHugePages() throws Exception {
    3.53 +    if (!canUse(UseTransparentHugePages(true))) {
    3.54 +      System.out.println("Skipping testUseTransparentHugePages");
    3.55 +      return;
    3.56 +    }
    3.57 +
    3.58 +    // -XX:-UseLargePages overrides all other flags.
    3.59 +    new FlagTester()
    3.60 +      .use(UseLargePages(false),
    3.61 +           UseTransparentHugePages(true))
    3.62 +      .expect(
    3.63 +           UseLargePages(false),
    3.64 +           UseTransparentHugePages(false),
    3.65 +           UseHugeTLBFS(false),
    3.66 +           UseSHM(false));
    3.67 +
    3.68 +    // Explicitly turn on UseTransparentHugePages.
    3.69 +    new FlagTester()
    3.70 +      .use(UseTransparentHugePages(true))
    3.71 +      .expect(
    3.72 +           UseLargePages(true),
    3.73 +           UseTransparentHugePages(true),
    3.74 +           UseHugeTLBFS(false),
    3.75 +           UseSHM(false));
    3.76 +
    3.77 +    new FlagTester()
    3.78 +      .use(UseLargePages(true),
    3.79 +           UseTransparentHugePages(true))
    3.80 +      .expect(
    3.81 +           UseLargePages(true),
    3.82 +           UseTransparentHugePages(true),
    3.83 +           UseHugeTLBFS(false),
    3.84 +           UseSHM(false));
    3.85 +
    3.86 +    // Setting a specific large pages flag will turn
    3.87 +    // off heuristics to choose large pages type.
    3.88 +    new FlagTester()
    3.89 +      .use(UseLargePages(true),
    3.90 +           UseTransparentHugePages(false))
    3.91 +      .expect(
    3.92 +           UseLargePages(false),
    3.93 +           UseTransparentHugePages(false),
    3.94 +           UseHugeTLBFS(false),
    3.95 +           UseSHM(false));
    3.96 +
    3.97 +    // Don't turn on UseTransparentHugePages
    3.98 +    // unless the user explicitly asks for them.
    3.99 +    new FlagTester()
   3.100 +      .use(UseLargePages(true))
   3.101 +      .expect(
   3.102 +           UseTransparentHugePages(false));
   3.103 +  }
   3.104 +
   3.105 +  public static void testUseHugeTLBFS() throws Exception {
   3.106 +    if (!canUse(UseHugeTLBFS(true))) {
   3.107 +      System.out.println("Skipping testUseHugeTLBFS");
   3.108 +      return;
   3.109 +    }
   3.110 +
   3.111 +    // -XX:-UseLargePages overrides all other flags.
   3.112 +    new FlagTester()
   3.113 +      .use(UseLargePages(false),
   3.114 +           UseHugeTLBFS(true))
   3.115 +      .expect(
   3.116 +           UseLargePages(false),
   3.117 +           UseTransparentHugePages(false),
   3.118 +           UseHugeTLBFS(false),
   3.119 +           UseSHM(false));
   3.120 +
   3.121 +    // Explicitly turn on UseHugeTLBFS.
   3.122 +    new FlagTester()
   3.123 +      .use(UseHugeTLBFS(true))
   3.124 +      .expect(
   3.125 +           UseLargePages(true),
   3.126 +           UseTransparentHugePages(false),
   3.127 +           UseHugeTLBFS(true),
   3.128 +           UseSHM(false));
   3.129 +
   3.130 +    new FlagTester()
   3.131 +      .use(UseLargePages(true),
   3.132 +           UseHugeTLBFS(true))
   3.133 +      .expect(
   3.134 +           UseLargePages(true),
   3.135 +           UseTransparentHugePages(false),
   3.136 +           UseHugeTLBFS(true),
   3.137 +           UseSHM(false));
   3.138 +
   3.139 +    // Setting a specific large pages flag will turn
   3.140 +    // off heuristics to choose large pages type.
   3.141 +    new FlagTester()
   3.142 +      .use(UseLargePages(true),
   3.143 +           UseHugeTLBFS(false))
   3.144 +      .expect(
   3.145 +           UseLargePages(false),
   3.146 +           UseTransparentHugePages(false),
   3.147 +           UseHugeTLBFS(false),
   3.148 +           UseSHM(false));
   3.149 +
   3.150 +    // Using UseLargePages will default to UseHugeTLBFS large pages.
   3.151 +    new FlagTester()
   3.152 +      .use(UseLargePages(true))
   3.153 +      .expect(
   3.154 +           UseLargePages(true),
   3.155 +           UseTransparentHugePages(false),
   3.156 +           UseHugeTLBFS(true),
   3.157 +           UseSHM(false));
   3.158 +  }
   3.159 +
   3.160 +  public static void testUseSHM() throws Exception {
   3.161 +    if (!canUse(UseSHM(true))) {
   3.162 +      System.out.println("Skipping testUseSHM");
   3.163 +      return;
   3.164 +    }
   3.165 +
   3.166 +    // -XX:-UseLargePages overrides all other flags.
   3.167 +    new FlagTester()
   3.168 +      .use(UseLargePages(false),
   3.169 +           UseSHM(true))
   3.170 +      .expect(
   3.171 +           UseLargePages(false),
   3.172 +           UseTransparentHugePages(false),
   3.173 +           UseHugeTLBFS(false),
   3.174 +           UseSHM(false));
   3.175 +
   3.176 +    // Explicitly turn on UseSHM.
   3.177 +    new FlagTester()
   3.178 +      .use(UseSHM(true))
   3.179 +      .expect(
   3.180 +           UseLargePages(true),
   3.181 +           UseTransparentHugePages(false),
   3.182 +           UseHugeTLBFS(false),
   3.183 +           UseSHM(true)) ;
   3.184 +
   3.185 +    new FlagTester()
   3.186 +      .use(UseLargePages(true),
   3.187 +           UseSHM(true))
   3.188 +      .expect(
   3.189 +           UseLargePages(true),
   3.190 +           UseTransparentHugePages(false),
   3.191 +           UseHugeTLBFS(false),
   3.192 +           UseSHM(true)) ;
   3.193 +
   3.194 +    // Setting a specific large pages flag will turn
   3.195 +    // off heuristics to choose large pages type.
   3.196 +    new FlagTester()
   3.197 +      .use(UseLargePages(true),
   3.198 +           UseSHM(false))
   3.199 +      .expect(
   3.200 +           UseLargePages(false),
   3.201 +           UseTransparentHugePages(false),
   3.202 +           UseHugeTLBFS(false),
   3.203 +           UseSHM(false));
   3.204 +
   3.205 +    // Setting UseLargePages can allow the system to choose
   3.206 +    // UseHugeTLBFS instead of UseSHM, but never UseTransparentHugePages.
   3.207 +    new FlagTester()
   3.208 +      .use(UseLargePages(true))
   3.209 +      .expect(
   3.210 +           UseLargePages(true),
   3.211 +           UseTransparentHugePages(false));
   3.212 +  }
   3.213 +
   3.214 +  public static void testCombinations() throws Exception {
   3.215 +    if (!canUse(UseSHM(true)) || !canUse(UseHugeTLBFS(true))) {
   3.216 +      System.out.println("Skipping testUseHugeTLBFSAndUseSHMCombination");
   3.217 +      return;
   3.218 +    }
   3.219 +
   3.220 +    // UseHugeTLBFS takes precedence over SHM.
   3.221 +
   3.222 +    new FlagTester()
   3.223 +      .use(UseLargePages(true),
   3.224 +           UseHugeTLBFS(true),
   3.225 +           UseSHM(true))
   3.226 +      .expect(
   3.227 +           UseLargePages(true),
   3.228 +           UseTransparentHugePages(false),
   3.229 +           UseHugeTLBFS(true),
   3.230 +           UseSHM(false));
   3.231 +
   3.232 +    new FlagTester()
   3.233 +      .use(UseLargePages(true),
   3.234 +           UseHugeTLBFS(false),
   3.235 +           UseSHM(true))
   3.236 +      .expect(
   3.237 +           UseLargePages(true),
   3.238 +           UseTransparentHugePages(false),
   3.239 +           UseHugeTLBFS(false),
   3.240 +           UseSHM(true));
   3.241 +
   3.242 +    new FlagTester()
   3.243 +      .use(UseLargePages(true),
   3.244 +           UseHugeTLBFS(true),
   3.245 +           UseSHM(false))
   3.246 +      .expect(
   3.247 +           UseLargePages(true),
   3.248 +           UseTransparentHugePages(false),
   3.249 +           UseHugeTLBFS(true),
   3.250 +           UseSHM(false));
   3.251 +
   3.252 +    new FlagTester()
   3.253 +      .use(UseLargePages(true),
   3.254 +           UseHugeTLBFS(false),
   3.255 +           UseSHM(false))
   3.256 +      .expect(
   3.257 +           UseLargePages(false),
   3.258 +           UseTransparentHugePages(false),
   3.259 +           UseHugeTLBFS(false),
   3.260 +           UseSHM(false));
   3.261 +
   3.262 +
   3.263 +    if (!canUse(UseTransparentHugePages(true))) {
   3.264 +      return;
   3.265 +    }
   3.266 +
   3.267 +    // UseTransparentHugePages takes precedence.
   3.268 +
   3.269 +    new FlagTester()
   3.270 +      .use(UseLargePages(true),
   3.271 +           UseTransparentHugePages(true),
   3.272 +           UseHugeTLBFS(true),
   3.273 +           UseSHM(true))
   3.274 +      .expect(
   3.275 +           UseLargePages(true),
   3.276 +           UseTransparentHugePages(true),
   3.277 +           UseHugeTLBFS(false),
   3.278 +           UseSHM(false));
   3.279 +
   3.280 +    new FlagTester()
   3.281 +      .use(UseTransparentHugePages(true),
   3.282 +           UseHugeTLBFS(true),
   3.283 +           UseSHM(true))
   3.284 +      .expect(
   3.285 +           UseLargePages(true),
   3.286 +           UseTransparentHugePages(true),
   3.287 +           UseHugeTLBFS(false),
   3.288 +           UseSHM(false));
   3.289 +  }
   3.290 +
   3.291 +  private static class FlagTester {
   3.292 +    private Flag [] useFlags;
   3.293 +
   3.294 +    public FlagTester use(Flag... useFlags) {
   3.295 +      this.useFlags = useFlags;
   3.296 +      return this;
   3.297 +    }
   3.298 +
   3.299 +    public void expect(Flag... expectedFlags) throws Exception {
   3.300 +      if (useFlags == null) {
   3.301 +        throw new IllegalStateException("Must run use() before expect()");
   3.302 +      }
   3.303 +
   3.304 +      OutputAnalyzer output = executeNewJVM(useFlags);
   3.305 +
   3.306 +      for (Flag flag : expectedFlags) {
   3.307 +        System.out.println("Looking for: " + flag.flagString());
   3.308 +        String strValue = output.firstMatch(".* " + flag.name() +  " .* :?= (\\S+).*", 1);
   3.309 +
   3.310 +        if (strValue == null) {
   3.311 +          throw new RuntimeException("Flag " + flag.name() + " couldn't be found");
   3.312 +        }
   3.313 +
   3.314 +        if (!flag.value().equals(strValue)) {
   3.315 +          throw new RuntimeException("Wrong value for: " + flag.name()
   3.316 +                                     + " expected: " + flag.value()
   3.317 +                                     + " got: " + strValue);
   3.318 +        }
   3.319 +      }
   3.320 +
   3.321 +      output.shouldHaveExitValue(0);
   3.322 +    }
   3.323 +  }
   3.324 +
   3.325 +  private static OutputAnalyzer executeNewJVM(Flag... flags) throws Exception {
   3.326 +    ArrayList<String> args = new ArrayList<>();
   3.327 +    for (Flag flag : flags) {
   3.328 +      args.add(flag.flagString());
   3.329 +    }
   3.330 +    args.add("-XX:+PrintFlagsFinal");
   3.331 +    args.add("-version");
   3.332 +
   3.333 +    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));
   3.334 +    OutputAnalyzer output = new OutputAnalyzer(pb.start());
   3.335 +
   3.336 +    return output;
   3.337 +  }
   3.338 +
   3.339 +  private static boolean canUse(Flag flag) {
   3.340 +    try {
   3.341 +      new FlagTester().use(flag).expect(flag);
   3.342 +    } catch (Exception e) {
   3.343 +      return false;
   3.344 +    }
   3.345 +
   3.346 +    return true;
   3.347 +  }
   3.348 +
   3.349 +  private static Flag UseLargePages(boolean value) {
   3.350 +    return new BooleanFlag("UseLargePages", value);
   3.351 +  }
   3.352 +
   3.353 +  private static Flag UseTransparentHugePages(boolean value) {
   3.354 +    return new BooleanFlag("UseTransparentHugePages", value);
   3.355 +  }
   3.356 +
   3.357 +  private static Flag UseHugeTLBFS(boolean value) {
   3.358 +    return new BooleanFlag("UseHugeTLBFS", value);
   3.359 +  }
   3.360 +
   3.361 +  private static Flag UseSHM(boolean value) {
   3.362 +    return new BooleanFlag("UseSHM", value);
   3.363 +  }
   3.364 +
   3.365 +  private static class BooleanFlag implements Flag {
   3.366 +    private String name;
   3.367 +    private boolean value;
   3.368 +
   3.369 +    BooleanFlag(String name, boolean value) {
   3.370 +      this.name = name;
   3.371 +      this.value = value;
   3.372 +    }
   3.373 +
   3.374 +    public String flagString() {
   3.375 +      return "-XX:" + (value ? "+" : "-") + name;
   3.376 +    }
   3.377 +
   3.378 +    public String name() {
   3.379 +      return name;
   3.380 +    }
   3.381 +
   3.382 +    public String value() {
   3.383 +      return Boolean.toString(value);
   3.384 +    }
   3.385 +  }
   3.386 +
   3.387 +  private static interface Flag {
   3.388 +    public String flagString();
   3.389 +    public String name();
   3.390 +    public String value();
   3.391 +  }
   3.392 +}

mercurial