Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions jcstress-core/src/main/java/org/openjdk/jcstress/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import joptsimple.OptionSpec;
import org.openjdk.jcstress.infra.runners.SpinLoopStyle;
import org.openjdk.jcstress.os.AffinityMode;
import org.openjdk.jcstress.properties.UsedProperties;
import org.openjdk.jcstress.util.OptionFormatter;
import org.openjdk.jcstress.util.StringUtils;
import org.openjdk.jcstress.util.TimeValue;
Expand All @@ -46,6 +47,8 @@
* @author Aleksey Shipilev (aleksey.shipilev@oracle.com)
*/
public class Options {
public static final String TIME_BUDGET_SWITCH = "tb";

private String resultDir;
private String testFilter;
private int strideSize;
Expand Down Expand Up @@ -93,7 +96,7 @@ public boolean parse() throws IOException {
.withRequiredArg().ofType(Integer.class).describedAs("N");

OptionSpec<Integer> strideCount = parser.accepts("strideCount", "Internal stride count per epoch. " +
"Larger value increases cache footprint.")
"Larger value increases cache footprint.")
.withRequiredArg().ofType(Integer.class).describedAs("N");

OptionSpec<Integer> optTime = parser.accepts("time", "(Deprecated, to be removed in next releases.)")
Expand Down Expand Up @@ -144,13 +147,13 @@ public boolean parse() throws IOException {
OptionSpec<Boolean> optPretouchHeap = parser.accepts("pth", "Pre-touch Java heap, if possible.")
.withOptionalArg().ofType(Boolean.class).describedAs("bool");

OptionSpec<TimeValue> optTimeBudget = parser.accepts("tb", "Time budget to run the tests. Harness code would try to fit the entire " +
OptionSpec<TimeValue> optTimeBudget = parser.accepts(TIME_BUDGET_SWITCH, "Time budget to run the tests. Harness code would try to fit the entire " +
"run in the desired timeframe. This value is expected to be reasonable, as it is not guaranteed that tests would succeed " +
"in arbitrarily low time budget. If not set, harness would try to decide a reasonable time, given the number of tests to run. " +
"Common time suffixes (s/m/h/d) are accepted.")
.withRequiredArg().ofType(TimeValue.class).describedAs("time");

parser.accepts("v", "Be verbose.");
parser.accepts("v", "Be verbose. Will print known properties in help");
parser.accepts("vv", "Be extra verbose.");
parser.accepts("vvv", "Be extra extra verbose.");
parser.accepts("h", "Print this help.");
Expand All @@ -161,12 +164,13 @@ public boolean parse() throws IOException {
} catch (OptionException e) {
System.err.println("ERROR: " + e.getMessage());
System.err.println();
parser.printHelpOn(System.err);
printHelp(parser, System.err);
return false;
}
setVerbosity(set);

if (set.has("h")) {
parser.printHelpOn(System.out);
printHelp(parser, System.out);
return false;
}

Expand All @@ -185,23 +189,14 @@ public boolean parse() throws IOException {
this.resultFile = "jcstress-results-" + timestamp + ".bin.gz";
}
this.list = orDefault(set.has(list), false);
if (set.has("vvv")) {
this.verbosity = new Verbosity(3);
} else if (set.has("vv")) {
this.verbosity = new Verbosity(2);
} else if (set.has("v")) {
this.verbosity = new Verbosity(1);
} else {
this.verbosity = new Verbosity(0);
}

int totalCpuCount = VMSupport.figureOutHotCPUs();
cpuCount = orDefault(set.valueOf(cpus), totalCpuCount);

if (cpuCount > totalCpuCount) {
System.err.println("Requested to use " + cpuCount + " CPUs, but system has only " + totalCpuCount + " CPUs.");
System.err.println();
parser.printHelpOn(System.err);
printHelp(parser, System.err);
return false;
}

Expand All @@ -227,21 +222,21 @@ public boolean parse() throws IOException {
if (optModeStr.value(set) != null) {
System.err.println("-m option is not supported anymore, please use -tb.");
System.err.println();
parser.printHelpOn(System.err);
printHelp(parser, System.err);
return false;
}

if (optTime.value(set) != null) {
System.err.println("-time option is not supported anymore, please use -tb.");
System.err.println();
parser.printHelpOn(System.err);
printHelp(parser, System.err);
return false;
}

if (optIters.value(set) != null) {
System.err.println("-iters option is not supported anymore, please use -tb.");
System.err.println();
parser.printHelpOn(System.err);
printHelp(parser, System.err);
return false;
}

Expand All @@ -263,6 +258,26 @@ public boolean parse() throws IOException {
return true;
}

private void setVerbosity(OptionSet set) {
if (set.has("vvv")) {
this.verbosity = new Verbosity(3);
} else if (set.has("vv")) {
this.verbosity = new Verbosity(2);
} else if (set.has("v")) {
this.verbosity = new Verbosity(1);
} else {
this.verbosity = new Verbosity(0);
}
}

private void printHelp(OptionParser parser, PrintStream ouer) throws IOException {
parser.printHelpOn(ouer);
ouer.println();
if (verbosity != null && verbosity.printAllTests()) {
UsedProperties.printHelpOn(ouer);
}
}

private List<String> processArgs(OptionSpec<String> op, OptionSet set) {
if (set.hasArgument(op)) {
try {
Expand Down Expand Up @@ -297,7 +312,7 @@ public void printSettingsOn(PrintStream out) {
out.printf(" Hardware CPUs in use: %d%n", getCPUCount());
out.printf(" Spinning style: %s%n", getSpinStyle());
out.printf(" Test selection: \"%s\"%n", getTestFilter());
out.printf(" Forks per test: %d normal, %d stress%n", getForks(), getForks()*getForksStressMultiplier());
out.printf(" Forks per test: %d normal, %d stress%n", getForks(), getForks() * getForksStressMultiplier());
out.printf(" Test stride: %d strides x %d tests, but taking no more than %d Mb%n", getStrideCount(), getStrideSize(), getMaxFootprintMb());
out.printf(" Test result blob: \"%s\"%n", resultFile);
out.printf(" Test results: \"%s\"%n", resultDir);
Expand Down Expand Up @@ -392,6 +407,8 @@ public boolean isPretouchHeap() {
return pretouchHeap;
}

public TimeValue timeBudget() { return timeBudget; }
public TimeValue timeBudget() {
return timeBudget;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.openjdk.jcstress;

import org.openjdk.jcstress.infra.grading.ReportUtils;
import org.openjdk.jcstress.properties.UsedProperties;
import org.openjdk.jcstress.util.TimeValue;
import org.openjdk.jcstress.vm.VMSupport;

Expand All @@ -34,9 +35,9 @@

public class TimeBudget {

static final int DEFAULT_PER_TEST_MS = Integer.getInteger("jcstress.timeBudget.defaultPerTestMs", 3000);
static final int MIN_TIME_MS = Integer.getInteger("jcstress.timeBudget.minTimeMs", 30);
static final int MAX_TIME_MS = Integer.getInteger("jcstress.timeBudget.maxTimeMs", 60_000);
static final int DEFAULT_PER_TEST_MS = UsedProperties.getJcstressTimeBudgetDefaultPerTestMs();
static final int MIN_TIME_MS = UsedProperties.getJcstressTimeBudgetMinTimeMs();
static final int MAX_TIME_MS = UsedProperties.getJcstressTimeBudgetMaxTimeMs();

final long endTime;
final int expectedTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.openjdk.jcstress.Options;
import org.openjdk.jcstress.TestExecutor;
import org.openjdk.jcstress.TimeBudget;
import org.openjdk.jcstress.properties.UsedProperties;
import org.openjdk.jcstress.Verbosity;
import org.openjdk.jcstress.infra.collectors.TestResult;
import org.openjdk.jcstress.infra.collectors.TestResultCollector;
Expand All @@ -43,8 +44,6 @@
*/
public class ConsoleReportPrinter implements TestResultCollector {

private static final Integer PRINT_INTERVAL_MS = Integer.getInteger("jcstress.console.printIntervalMs");

private final Verbosity verbosity;
private final PrintWriter output;

Expand Down Expand Up @@ -80,13 +79,11 @@ public ConsoleReportPrinter(Options opts, PrintWriter pw, long expectedForks, Ti
Arrays.fill(progressLen, 1);

progressFirstLine = true;
progressInteractive = (System.console() != null);
progressInteractive = UsedProperties.isProgressInteractive();
progressAnsi = VMSupport.isLinux();
output.println(" Attached the " + (progressInteractive ? "interactive console" : "non-interactive output stream") + ".");

printIntervalMs = (PRINT_INTERVAL_MS != null) ?
PRINT_INTERVAL_MS :
progressInteractive ? 1_000 : 15_000;
printIntervalMs = UsedProperties.getPrintIntervalMs();

output.println(" Printing the progress line at most every " + printIntervalMs + " milliseconds.");
output.println();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.openjdk.jcstress.link;

import org.openjdk.jcstress.properties.UsedProperties;
import org.openjdk.jcstress.infra.collectors.TestResult;
import org.openjdk.jcstress.infra.runners.ForkedTestConfig;

Expand All @@ -32,7 +33,7 @@

public final class BinaryLinkClient {

private static final int LINK_TIMEOUT_MS = Integer.getInteger("jcstress.link.timeoutMs", 30 * 1000);
private static final int LINK_TIMEOUT_MS = UsedProperties.getJcstressLinkTimeoutMs();

private final String hostName;
private final int hostPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package org.openjdk.jcstress.link;

import org.openjdk.jcstress.properties.UsedProperties;
import org.openjdk.jcstress.infra.collectors.TestResult;
import org.openjdk.jcstress.infra.runners.ForkedTestConfig;

Expand All @@ -37,9 +38,8 @@
*/
public final class BinaryLinkServer {

private static final String LINK_ADDRESS = System.getProperty("jcstress.link.address");
private static final int LINK_PORT = Integer.getInteger("jcstress.link.port", 0);
private static final int LINK_TIMEOUT_MS = Integer.getInteger("jcstress.link.timeoutMs", 30 * 1000);
private static final int LINK_PORT = UsedProperties.getJcstressLinkPort();
private static final int LINK_TIMEOUT_MS = UsedProperties.getJcstressLinkTimeoutMs();

private final ServerSocket server;
private final InetAddress listenAddress;
Expand All @@ -49,27 +49,15 @@ public final class BinaryLinkServer {
public BinaryLinkServer(ServerListener listener) throws IOException {
this.listener = listener;

listenAddress = getListenAddress();
listenAddress = UsedProperties.getListenAddress();
server = new ServerSocket(LINK_PORT, 50, listenAddress);
server.setSoTimeout(LINK_TIMEOUT_MS);

handler = new Handler(server);
handler.start();
}

private InetAddress getListenAddress() {
// Try to use user-provided override first.
if (LINK_ADDRESS != null) {
try {
return InetAddress.getByName(LINK_ADDRESS);
} catch (UnknownHostException e) {
// override failed, notify user
throw new IllegalStateException("Can not initialize binary link.", e);
}
}

return InetAddress.getLoopbackAddress();
}

public void terminate() {
// set interrupt flag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2005, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/

package org.openjdk.jcstress.properties;

import java.util.Arrays;
import java.util.List;

class ForkedVmProperties implements UsedProperties.ProeprtiesHelpProvider {

static final UsedProperties.StringJcstressProperty LINK_ADDRESS = new UsedProperties.StringJcstressProperty("jcstress.link.address", new String[]{null}) {
@Override
public String getDescription() {
return getKey() + " is address where to connect to forked VMs. Defaults to loop-back. Set to '" + getListenAddressForInfo() + "'";
}
};


static final UsedProperties.IntJcstressProperty LINK_PORT = new UsedProperties.IntJcstressProperty("jcstress.link.port", 0) {
@Override
public String getDescription() {
return getKey() + " is port where to connect to forked VMs on " + LINK_ADDRESS.getKey() + ". Defaults to " + getDefault() + " (random free port)." +
" Set to " + UsedProperties.getJcstressLinkPort();
}
};

static final UsedProperties.IntJcstressProperty LINK_TIMEOUTMS = new UsedProperties.IntJcstressProperty("jcstress.link.timeoutMs", 30 * 1000) {
@Override
public String getDescription() {
return getKey() + " set timeout to forked VM communication ms." +
" Defaults to " + getDefault() + "ms. Set to " + getValue() + "ms.";
}
};


private static String getListenAddressForInfo() {
try {
return UsedProperties.getListenAddress().toString();
} catch (Exception ex) {
return ex.getMessage();
}
}

@Override
public List<String> getHelp() {
return Arrays.asList(
LINK_ADDRESS.getDescription(),
LINK_PORT.getDescription(),
LINK_TIMEOUTMS.getDescription());
}

@Override
public String getTitle() {
return "Properties handling forked VMs. Modify only if you are sure what youa re doing";
}

}
Loading