changeset 6197:3c9392f1ee18

6521376: MaxTenuringThreshold and AlwayTenure/NeverTenure consistency Summary: Adapt InitialTenuringThreshold and MaxTenuringThreshold according to AlwaysTenure/NeverTenure flag setting. Reviewed-by: jmasa, tschatzl
author tamao
date Wed, 26 Mar 2014 12:49:34 +0100
parents 85151870938f
children 05cabffad645
files src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp src/share/vm/gc_implementation/shared/ageTable.cpp src/share/vm/runtime/arguments.cpp test/gc/arguments/FlagsValue.java test/gc/arguments/TestInitialTenuringThreshold.java test/gc/arguments/TestObjectTenuringFlags.java
diffstat 6 files changed, 313 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp	Wed Mar 26 10:54:52 2014 +0100
+++ b/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp	Wed Mar 26 12:49:34 2014 +0100
@@ -550,7 +550,8 @@
 
        if (PrintTenuringDistribution) {
          gclog_or_tty->cr();
-         gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold %u (max %u)",
+         gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold "
+                                UINTX_FORMAT " (max threshold " UINTX_FORMAT ")",
                                 size_policy->calculated_survivor_size_in_bytes(),
                                 _tenuring_threshold, MaxTenuringThreshold);
        }
@@ -829,10 +830,10 @@
 void PSScavenge::initialize() {
   // Arguments must have been parsed
 
-  if (AlwaysTenure) {
-    _tenuring_threshold = 0;
-  } else if (NeverTenure) {
-    _tenuring_threshold = markOopDesc::max_age + 1;
+  if (AlwaysTenure || NeverTenure) {
+    assert(MaxTenuringThreshold == 0 || MaxTenuringThreshold == markOopDesc::max_age + 1,
+        err_msg("MaxTenuringThreshold should be 0 or markOopDesc::max_age + 1, but is ", MaxTenuringThreshold));
+    _tenuring_threshold = MaxTenuringThreshold;
   } else {
     // We want to smooth out our startup times for the AdaptiveSizePolicy
     _tenuring_threshold = (UseAdaptiveSizePolicy) ? InitialTenuringThreshold :
--- a/src/share/vm/gc_implementation/shared/ageTable.cpp	Wed Mar 26 10:54:52 2014 +0100
+++ b/src/share/vm/gc_implementation/shared/ageTable.cpp	Wed Mar 26 12:49:34 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,28 +80,37 @@
 
 uint ageTable::compute_tenuring_threshold(size_t survivor_capacity) {
   size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100);
-  size_t total = 0;
-  uint age = 1;
-  assert(sizes[0] == 0, "no objects with age zero should be recorded");
-  while (age < table_size) {
-    total += sizes[age];
-    // check if including objects of age 'age' made us pass the desired
-    // size, if so 'age' is the new threshold
-    if (total > desired_survivor_size) break;
-    age++;
+  uint result;
+
+  if (AlwaysTenure || NeverTenure) {
+    assert(MaxTenuringThreshold == 0 || MaxTenuringThreshold == markOopDesc::max_age + 1,
+        err_msg("MaxTenuringThreshold should be 0 or markOopDesc::max_age + 1, but is ", MaxTenuringThreshold));
+    result = MaxTenuringThreshold;
+  } else {
+    size_t total = 0;
+    uint age = 1;
+    assert(sizes[0] == 0, "no objects with age zero should be recorded");
+    while (age < table_size) {
+      total += sizes[age];
+      // check if including objects of age 'age' made us pass the desired
+      // size, if so 'age' is the new threshold
+      if (total > desired_survivor_size) break;
+      age++;
+    }
+    result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
   }
-  uint result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
 
   if (PrintTenuringDistribution || UsePerfData) {
 
     if (PrintTenuringDistribution) {
       gclog_or_tty->cr();
-      gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold %u (max %u)",
+      gclog_or_tty->print_cr("Desired survivor size " SIZE_FORMAT " bytes, new threshold "
+        UINTX_FORMAT " (max threshold " UINTX_FORMAT ")",
         desired_survivor_size*oopSize, result, MaxTenuringThreshold);
     }
 
-    total = 0;
-    age = 1;
+    size_t total = 0;
+    uint age = 1;
     while (age < table_size) {
       total += sizes[age];
       if (sizes[age] > 0) {
--- a/src/share/vm/runtime/arguments.cpp	Wed Mar 26 10:54:52 2014 +0100
+++ b/src/share/vm/runtime/arguments.cpp	Wed Mar 26 12:49:34 2014 +0100
@@ -1186,11 +1186,6 @@
     FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
   }
 
-  // AlwaysTenure flag should make ParNew promote all at first collection.
-  // See CR 6362902.
-  if (AlwaysTenure) {
-    FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0);
-  }
   // When using compressed oops, we use local overflow stacks,
   // rather than using a global overflow list chained through
   // the klass word of the object's pre-image.
@@ -2343,10 +2338,8 @@
   status = status && verify_percentage(YoungGenerationSizeSupplement, "YoungGenerationSizeSupplement");
   status = status && verify_percentage(TenuredGenerationSizeSupplement, "TenuredGenerationSizeSupplement");
 
-  // the "age" field in the oop header is 4 bits; do not want to pull in markOop.hpp
-  // just for that, so hardcode here.
-  status = status && verify_interval(MaxTenuringThreshold, 0, 15, "MaxTenuringThreshold");
-  status = status && verify_interval(InitialTenuringThreshold, 0, MaxTenuringThreshold, "MaxTenuringThreshold");
+  status = status && verify_interval(MaxTenuringThreshold, 0, markOopDesc::max_age + 1, "MaxTenuringThreshold");
+  status = status && verify_interval(InitialTenuringThreshold, 0, MaxTenuringThreshold, "InitialTenuringThreshold");
   status = status && verify_percentage(TargetSurvivorRatio, "TargetSurvivorRatio");
   status = status && verify_percentage(MarkSweepDeadRatio, "MarkSweepDeadRatio");
 
@@ -3072,14 +3065,31 @@
       // but disallow DR and offlining (5008695).
       FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
 
+    // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure;
+    // and the last option wins.
     } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
-      // The last option must always win.
+      FLAG_SET_CMDLINE(bool, NeverTenure, true);
       FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
-      FLAG_SET_CMDLINE(bool, NeverTenure, true);
+      FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1);
     } else if (match_option(option, "-XX:+AlwaysTenure", &tail)) {
-      // The last option must always win.
       FLAG_SET_CMDLINE(bool, NeverTenure, false);
       FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
+      FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0);
+    } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) {
+      uintx max_tenuring_thresh = 0;
+      if(!parse_uintx(tail, &max_tenuring_thresh, 0)) {
+        jio_fprintf(defaultStream::error_stream(),
+                    "Invalid MaxTenuringThreshold: %s\n", option->optionString);
+      }
+      FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh);
+
+      if (MaxTenuringThreshold == 0) {
+        FLAG_SET_CMDLINE(bool, NeverTenure, false);
+        FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
+      } else {
+        FLAG_SET_CMDLINE(bool, NeverTenure, false);
+        FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
+      }
     } else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) ||
                match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) {
       jio_fprintf(defaultStream::error_stream(),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/gc/arguments/FlagsValue.java	Wed Mar 26 12:49:34 2014 +0100
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* This code is free software; you can redistribute it and/or modify it
+* under the terms of the GNU General Public License version 2 only, as
+* published by the Free Software Foundation.
+*
+* This code is distributed in the hope that it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+* version 2 for more details (a copy is included in the LICENSE file that
+* accompanied this code).
+*
+* You should have received a copy of the GNU General Public License version
+* 2 along with this work; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+*
+* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+* or visit www.oracle.com if you need additional information or have any
+* questions.
+*/
+
+import java.util.regex.*;
+
+public class FlagsValue {
+  public static boolean getFlagBoolValue(String flag, String where) {
+    Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
+    if (!m.find()) {
+      throw new RuntimeException("Could not find value for flag " + flag + " in output string");
+    }
+    return m.group(1).equals("true");
+  }
+
+  public static long getFlagLongValue(String flag, String where) {
+    Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
+    if (!m.find()) {
+      throw new RuntimeException("Could not find value for flag " + flag + " in output string");
+    }
+    String match = m.group();
+    return Long.parseLong(match.substring(match.lastIndexOf(" ") + 1, match.length()));
+  }
+}
\ No newline at end of file
--- a/test/gc/arguments/TestInitialTenuringThreshold.java	Wed Mar 26 10:54:52 2014 +0100
+++ b/test/gc/arguments/TestInitialTenuringThreshold.java	Wed Mar 26 12:49:34 2014 +0100
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
@@ -63,13 +63,13 @@
     // successful tests
     runWithThresholds(0, 10, false);
     runWithThresholds(5, 5, false);
+    runWithThresholds(8, 16, false);
     // failing tests
     runWithThresholds(10, 0, true);
     runWithThresholds(9, 8, true);
     runWithThresholds(-1, 8, true);
     runWithThresholds(8, -1, true);
-    runWithThresholds(8, 16, true);
     runWithThresholds(16, 8, true);
+    runWithThresholds(8, 17, true);
   }
-}
-
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/gc/arguments/TestObjectTenuringFlags.java	Wed Mar 26 12:49:34 2014 +0100
@@ -0,0 +1,215 @@
+/*
+* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* This code is free software; you can redistribute it and/or modify it
+* under the terms of the GNU General Public License version 2 only, as
+* published by the Free Software Foundation.
+*
+* This code is distributed in the hope that it will be useful, but WITHOUT
+* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+* version 2 for more details (a copy is included in the LICENSE file that
+* accompanied this code).
+*
+* You should have received a copy of the GNU General Public License version
+* 2 along with this work; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+*
+* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+* or visit www.oracle.com if you need additional information or have any
+* questions.
+*/
+
+/*
+ * @test TestObjectTenuringFlags
+ * @key gc
+ * @bug 6521376
+ * @summary Tests argument processing for NeverTenure, AlwaysTenure,
+ * and MaxTenuringThreshold
+ * @library /testlibrary
+ * @build TestObjectTenuringFlags FlagsValue
+ * @run main/othervm TestObjectTenuringFlags
+ */
+
+import com.oracle.java.testlibrary.*;
+
+import java.util.*;
+
+public class TestObjectTenuringFlags {
+  public static void main(String args[]) throws Exception {
+    // default case
+    runTenuringFlagsConsistencyTest(
+        new String[]{},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 15));
+
+    // valid cases
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:+NeverTenure"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, true /* neverTenure */, 7, 16));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:+AlwaysTenure"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=0"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=5"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 5, 5));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=10"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 10));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=15"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 15));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=16"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 16));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:InitialTenuringThreshold=0"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 0, 15));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:InitialTenuringThreshold=5"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 5, 15));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:InitialTenuringThreshold=10"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 10, 15));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:InitialTenuringThreshold=15"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 15, 15));
+
+    // "Last option wins" cases
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:+AlwaysTenure", "-XX:+NeverTenure"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, true /* neverTenure */, 7, 16));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:+NeverTenure", "-XX:+AlwaysTenure"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=16", "-XX:+AlwaysTenure"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:+AlwaysTenure", "-XX:MaxTenuringThreshold=16"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 16));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=0", "-XX:+NeverTenure"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(false /* alwaysTenure */, true /* neverTenure */, 7, 16));
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:+NeverTenure", "-XX:MaxTenuringThreshold=0"},
+        false /* shouldFail */,
+        new ExpectedTenuringFlags(true /* alwaysTenure */, false /* neverTenure */, 0, 0));
+
+    // Illegal cases
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:MaxTenuringThreshold=17"},
+        true /* shouldFail */,
+        new ExpectedTenuringFlags());
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:InitialTenuringThreshold=16"},
+        true /* shouldFail */,
+        new ExpectedTenuringFlags());
+
+    runTenuringFlagsConsistencyTest(
+        new String[]{"-XX:InitialTenuringThreshold=17"},
+        true /* shouldFail */,
+        new ExpectedTenuringFlags());
+  }
+
+  private static void runTenuringFlagsConsistencyTest(String[] tenuringFlags,
+          boolean shouldFail,
+          ExpectedTenuringFlags expectedFlags) throws Exception {
+    List<String> vmOpts = new ArrayList<>();
+    if (tenuringFlags.length > 0) {
+      Collections.addAll(vmOpts, tenuringFlags);
+    }
+    Collections.addAll(vmOpts, "-XX:+PrintFlagsFinal", "-version");
+
+    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
+    OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+    if (shouldFail) {
+      output.shouldHaveExitValue(1);
+    } else {
+      output.shouldHaveExitValue(0);
+      String stdout = output.getStdout();
+      checkTenuringFlagsConsistency(stdout, expectedFlags);
+    }
+  }
+
+  private static void checkTenuringFlagsConsistency(String output, ExpectedTenuringFlags expectedFlags) {
+    if (expectedFlags.alwaysTenure != FlagsValue.getFlagBoolValue("AlwaysTenure", output)) {
+      throw new RuntimeException(
+            "Actual flag AlwaysTenure " + FlagsValue.getFlagBoolValue("AlwaysTenure", output) +
+            " is not equal to expected flag AlwaysTenure " + expectedFlags.alwaysTenure);
+    }
+
+    if (expectedFlags.neverTenure != FlagsValue.getFlagBoolValue("NeverTenure", output)) {
+      throw new RuntimeException(
+            "Actual flag NeverTenure " + FlagsValue.getFlagBoolValue("NeverTenure", output) +
+            " is not equal to expected flag NeverTenure " + expectedFlags.neverTenure);
+    }
+
+    if (expectedFlags.initialTenuringThreshold != FlagsValue.getFlagLongValue("InitialTenuringThreshold", output)) {
+      throw new RuntimeException(
+            "Actual flag InitialTenuringThreshold " + FlagsValue.getFlagLongValue("InitialTenuringThreshold", output) +
+            " is not equal to expected flag InitialTenuringThreshold " + expectedFlags.initialTenuringThreshold);
+    }
+
+    if (expectedFlags.maxTenuringThreshold != FlagsValue.getFlagLongValue("MaxTenuringThreshold", output)) {
+      throw new RuntimeException(
+            "Actual flag MaxTenuringThreshold " + FlagsValue.getFlagLongValue("MaxTenuringThreshold", output) +
+            " is not equal to expected flag MaxTenuringThreshold " + expectedFlags.maxTenuringThreshold);
+    }
+  }
+}
+
+class ExpectedTenuringFlags {
+    public boolean alwaysTenure;
+    public boolean neverTenure;
+    public long initialTenuringThreshold;
+    public long maxTenuringThreshold;
+
+    public ExpectedTenuringFlags(boolean alwaysTenure,
+            boolean neverTenure,
+            long initialTenuringThreshold,
+            long maxTenuringThreshold) {
+      this.alwaysTenure = alwaysTenure;
+      this.neverTenure = neverTenure;
+      this.initialTenuringThreshold = initialTenuringThreshold;
+      this.maxTenuringThreshold = maxTenuringThreshold;
+    }
+    public ExpectedTenuringFlags() {}
+}