# HG changeset patch # User mgerdin # Date 1381836561 25200 # Node ID 82fcc0567fefbe3a99e9045d32c2be3ade9c9cbd # Parent d6818f623792d3761210dc4e206214d71d9def04# Parent 027006a47a6df5ddef2a3ffab9ae5addd7a0d196 Merge diff -r d6818f623792 -r 82fcc0567fef src/share/vm/runtime/arguments.cpp --- a/src/share/vm/runtime/arguments.cpp Tue Oct 15 11:18:42 2013 +0200 +++ b/src/share/vm/runtime/arguments.cpp Tue Oct 15 04:29:21 2013 -0700 @@ -2694,8 +2694,9 @@ FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size); // Xmaxf } else if (match_option(option, "-Xmaxf", &tail)) { - int maxf = (int)(atof(tail) * 100); - if (maxf < 0 || maxf > 100) { + char* err; + int maxf = (int)(strtod(tail, &err) * 100); + if (*err != '\0' || maxf < 0 || maxf > 100) { jio_fprintf(defaultStream::error_stream(), "Bad max heap free percentage size: %s\n", option->optionString); @@ -2705,8 +2706,9 @@ } // Xminf } else if (match_option(option, "-Xminf", &tail)) { - int minf = (int)(atof(tail) * 100); - if (minf < 0 || minf > 100) { + char* err; + int minf = (int)(strtod(tail, &err) * 100); + if (*err != '\0' || minf < 0 || minf > 100) { jio_fprintf(defaultStream::error_stream(), "Bad min heap free percentage size: %s\n", option->optionString); diff -r d6818f623792 -r 82fcc0567fef test/gc/arguments/TestHeapFreeRatio.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/gc/arguments/TestHeapFreeRatio.java Tue Oct 15 04:29:21 2013 -0700 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2013, 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 TestHeapFreeRatio + * @key gc + * @bug 8025661 + * @summary Test parsing of -Xminf and -Xmaxf + * @library /testlibrary + * @run main/othervm TestHeapFreeRatio + */ + +import com.oracle.java.testlibrary.*; + +public class TestHeapFreeRatio { + + enum Validation { + VALID, + MIN_INVALID, + MAX_INVALID, + COMBINATION_INVALID + } + + private static void testMinMaxFreeRatio(String min, String max, Validation type) throws Exception { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( + "-Xminf" + min, + "-Xmaxf" + max, + "-version"); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + + switch (type) { + case VALID: + output.shouldNotContain("Error"); + output.shouldHaveExitValue(0); + break; + case MIN_INVALID: + output.shouldContain("Bad min heap free percentage size: -Xminf" + min); + output.shouldContain("Error"); + output.shouldHaveExitValue(1); + break; + case MAX_INVALID: + output.shouldContain("Bad max heap free percentage size: -Xmaxf" + max); + output.shouldContain("Error"); + output.shouldHaveExitValue(1); + break; + case COMBINATION_INVALID: + output.shouldContain("must be less than or equal to MaxHeapFreeRatio"); + output.shouldContain("Error"); + output.shouldHaveExitValue(1); + break; + default: + throw new IllegalStateException("Must specify expected validation type"); + } + + System.out.println(output.getOutput()); + } + + public static void main(String args[]) throws Exception { + testMinMaxFreeRatio( "0.1", "0.5", Validation.VALID); + testMinMaxFreeRatio( ".1", ".5", Validation.VALID); + testMinMaxFreeRatio( "0.5", "0.5", Validation.VALID); + + testMinMaxFreeRatio("-0.1", "0.5", Validation.MIN_INVALID); + testMinMaxFreeRatio( "1.1", "0.5", Validation.MIN_INVALID); + testMinMaxFreeRatio("=0.1", "0.5", Validation.MIN_INVALID); + testMinMaxFreeRatio("0.1f", "0.5", Validation.MIN_INVALID); + testMinMaxFreeRatio( + "INVALID", "0.5", Validation.MIN_INVALID); + testMinMaxFreeRatio( + "2147483647", "0.5", Validation.MIN_INVALID); + + testMinMaxFreeRatio( "0.1", "-0.5", Validation.MAX_INVALID); + testMinMaxFreeRatio( "0.1", "1.5", Validation.MAX_INVALID); + testMinMaxFreeRatio( "0.1", "0.5f", Validation.MAX_INVALID); + testMinMaxFreeRatio( "0.1", "=0.5", Validation.MAX_INVALID); + testMinMaxFreeRatio( + "0.1", "INVALID", Validation.MAX_INVALID); + testMinMaxFreeRatio( + "0.1", "2147483647", Validation.MAX_INVALID); + + testMinMaxFreeRatio( "0.5", "0.1", Validation.COMBINATION_INVALID); + testMinMaxFreeRatio( ".5", ".10", Validation.COMBINATION_INVALID); + testMinMaxFreeRatio("0.12","0.100", Validation.COMBINATION_INVALID); + } +}