< prev index next >

test/gc/arguments/TestObjectTenuringFlags.java

Print this page
rev 8944 : [mq]: 8078555_latest


   8 *
   9 * This code is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 * version 2 for more details (a copy is included in the LICENSE file that
  13 * accompanied this code).
  14 *
  15 * You should have received a copy of the GNU General Public License version
  16 * 2 along with this work; if not, write to the Free Software Foundation,
  17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 *
  19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 * or visit www.oracle.com if you need additional information or have any
  21 * questions.
  22 */
  23 
  24 /*
  25  * @test TestObjectTenuringFlags
  26  * @key gc
  27  * @bug 6521376

  28  * @summary Tests argument processing for NeverTenure, AlwaysTenure,
  29  * and MaxTenuringThreshold
  30  * @library /testlibrary
  31  * @modules java.base/sun.misc
  32  *          java.management
  33  * @build TestObjectTenuringFlags FlagsValue
  34  * @run main/othervm TestObjectTenuringFlags
  35  */
  36 
  37 import jdk.test.lib.*;
  38 
  39 import java.util.*;
  40 
  41 public class TestObjectTenuringFlags {
  42   public static void main(String args[]) throws Exception {
  43     // default case
  44     runTenuringFlagsConsistencyTest(
  45         new String[]{},
  46         false /* shouldFail */,
  47         new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 15));


 140         new ExpectedTenuringFlags());
 141 
 142     runTenuringFlagsConsistencyTest(
 143         new String[]{"-XX:InitialTenuringThreshold=16"},
 144         true /* shouldFail */,
 145         new ExpectedTenuringFlags());
 146 
 147     runTenuringFlagsConsistencyTest(
 148         new String[]{"-XX:InitialTenuringThreshold=17"},
 149         true /* shouldFail */,
 150         new ExpectedTenuringFlags());
 151   }
 152 
 153   private static void runTenuringFlagsConsistencyTest(String[] tenuringFlags,
 154           boolean shouldFail,
 155           ExpectedTenuringFlags expectedFlags) throws Exception {
 156     List<String> vmOpts = new ArrayList<>();
 157     if (tenuringFlags.length > 0) {
 158       Collections.addAll(vmOpts, tenuringFlags);
 159     }
 160     Collections.addAll(vmOpts, "-XX:+PrintFlagsFinal", "-version");
 161 
 162     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
 163     OutputAnalyzer output = new OutputAnalyzer(pb.start());
 164 
 165     if (shouldFail) {
 166       output.shouldHaveExitValue(1);
 167     } else {
 168       output.shouldHaveExitValue(0);
 169       String stdout = output.getStdout();
 170       checkTenuringFlagsConsistency(stdout, expectedFlags);
 171     }
 172   }
 173 
 174   private static void checkTenuringFlagsConsistency(String output, ExpectedTenuringFlags expectedFlags) {
 175     if (expectedFlags.alwaysTenure != FlagsValue.getFlagBoolValue("AlwaysTenure", output)) {
 176       throw new RuntimeException(
 177             "Actual flag AlwaysTenure " + FlagsValue.getFlagBoolValue("AlwaysTenure", output) +
 178             " is not equal to expected flag AlwaysTenure " + expectedFlags.alwaysTenure);
 179     }
 180 




   8 *
   9 * This code is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 * version 2 for more details (a copy is included in the LICENSE file that
  13 * accompanied this code).
  14 *
  15 * You should have received a copy of the GNU General Public License version
  16 * 2 along with this work; if not, write to the Free Software Foundation,
  17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 *
  19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 * or visit www.oracle.com if you need additional information or have any
  21 * questions.
  22 */
  23 
  24 /*
  25  * @test TestObjectTenuringFlags
  26  * @key gc
  27  * @bug 6521376
  28  * @requires vm.gc=="Parallel"
  29  * @summary Tests argument processing for NeverTenure, AlwaysTenure,
  30  * and MaxTenuringThreshold
  31  * @library /testlibrary
  32  * @modules java.base/sun.misc
  33  *          java.management
  34  * @build TestObjectTenuringFlags FlagsValue
  35  * @run main/othervm TestObjectTenuringFlags
  36  */
  37 
  38 import jdk.test.lib.*;
  39 
  40 import java.util.*;
  41 
  42 public class TestObjectTenuringFlags {
  43   public static void main(String args[]) throws Exception {
  44     // default case
  45     runTenuringFlagsConsistencyTest(
  46         new String[]{},
  47         false /* shouldFail */,
  48         new ExpectedTenuringFlags(false /* alwaysTenure */, false /* neverTenure */, 7, 15));


 141         new ExpectedTenuringFlags());
 142 
 143     runTenuringFlagsConsistencyTest(
 144         new String[]{"-XX:InitialTenuringThreshold=16"},
 145         true /* shouldFail */,
 146         new ExpectedTenuringFlags());
 147 
 148     runTenuringFlagsConsistencyTest(
 149         new String[]{"-XX:InitialTenuringThreshold=17"},
 150         true /* shouldFail */,
 151         new ExpectedTenuringFlags());
 152   }
 153 
 154   private static void runTenuringFlagsConsistencyTest(String[] tenuringFlags,
 155           boolean shouldFail,
 156           ExpectedTenuringFlags expectedFlags) throws Exception {
 157     List<String> vmOpts = new ArrayList<>();
 158     if (tenuringFlags.length > 0) {
 159       Collections.addAll(vmOpts, tenuringFlags);
 160     }
 161     Collections.addAll(vmOpts, "-XX:+UseParallelGC", "-XX:+PrintFlagsFinal", "-version");
 162 
 163     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
 164     OutputAnalyzer output = new OutputAnalyzer(pb.start());
 165 
 166     if (shouldFail) {
 167       output.shouldHaveExitValue(1);
 168     } else {
 169       output.shouldHaveExitValue(0);
 170       String stdout = output.getStdout();
 171       checkTenuringFlagsConsistency(stdout, expectedFlags);
 172     }
 173   }
 174 
 175   private static void checkTenuringFlagsConsistency(String output, ExpectedTenuringFlags expectedFlags) {
 176     if (expectedFlags.alwaysTenure != FlagsValue.getFlagBoolValue("AlwaysTenure", output)) {
 177       throw new RuntimeException(
 178             "Actual flag AlwaysTenure " + FlagsValue.getFlagBoolValue("AlwaysTenure", output) +
 179             " is not equal to expected flag AlwaysTenure " + expectedFlags.alwaysTenure);
 180     }
 181 


< prev index next >