undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,50 @@
This directory contains the juicer and two benchmark tests.
Taken together, these tests form the RMI reliability
suite. These three tests each function in two modes:
1) as short running JTREG regression tests
2) as long running RMI reliability tests
In addition, the two benchmark tests serves a third role:
3) as RMI and Serialization Performance tests run by
the Performance Group (http://perfwww.ireland/)
All of the ksh scripts under this directory are used
to run the RMI reliability suite and are not used
to run the JTREG regression tests. The one exception
to this is the scripts/create_benchmark_jars.ksh
script which creates the JAR files for the benchmarks
that are transfered to the Performance Group.
------------------------------------------------------
The remainder of this file describes how to run the
RMI reliability suite:
The launch_reliability.ksh script will build the
reliability suite, execute it, and clean up after itself.
It can be run from any directory with the proper
command line args.
For example, to run for 72 hours:
export SUITE_DIR=<path to this directory>
export JDK_DIR=<path to JDK being tested>
export RES_DIR=<path to results dir for this run>
export WORK_DIR=<path to temp working dir for this run>
export VMOPTS="-server -showversion"
rm -rf $RES_DIR $WORK_DIR
mkdir -p $RES_DIR $WORK_DIR
${SUITE_DIR}/launch_reliability.ksh \
$JDK_DIR \
$WORK_DIR \
$RES_DIR \
ksh \
$SUITE_DIR \
72 \
$VMOPTS >> $RES_DIR/launch_reliability.log 2>&1 &

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
/**
* Information about a benchmark: its name, how long it took to run, and the
* weight associated with it (for calculating the overall score).
*/
public class BenchInfo {
Benchmark benchmark;
String name;
long time;
float weight;
String[] args;
/**
* Construct benchmark info.
*/
BenchInfo(Benchmark benchmark, String name, float weight, String[] args) {
this.benchmark = benchmark;
this.name = name;
this.weight = weight;
this.args = args;
this.time = -1;
}
/**
* Run benchmark with specified args. Called only by the harness.
*/
void runBenchmark() throws Exception {
time = benchmark.run(args);
}
/**
* Return the benchmark for this benchmark info.
*/
public Benchmark getBenchmark() {
return benchmark;
}
/**
* Return the name of this benchmark.
*/
public String getName() {
return name;
}
/**
* Return the execution time for benchmark, or -1 if benchmark hasn't been
* run to completion.
*/
public long getTime() {
return time;
}
/**
* Return weight associated with benchmark.
*/
public float getWeight() {
return weight;
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
/**
* Interface that each benchmark must implement.
*/
public interface Benchmark {
/**
* Run the benchmark. Return length of time (in milliseconds) that run
* took.
*/
long run(String[] args) throws Exception;
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
/**
* Exception that is thrown if harness config file doesn't obey proper syntax.
*/
public class ConfigFormatException extends Exception {
/**
* Construct blank ConfigFormatException.
*/
public ConfigFormatException() {
}
/**
* Construct new ConfigFormatException with the given error string.
*/
public ConfigFormatException(String s) {
super(s);
}
}

View file

@ -0,0 +1,235 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.io.IOException;
import java.util.Vector;
/**
* Benchmark harness. Responsible for parsing config file and running
* benchmarks.
*/
public class Harness {
BenchInfo[] binfo;
/**
* Create new benchmark harness with given configuration and reporter.
* Throws ConfigFormatException if there was an error parsing the config
* file.
* <p>
* <b>Config file syntax:</b>
* <p>
* '#' marks the beginning of a comment. Blank lines are ignored. All
* other lines should adhere to the following format:
* <pre>
* &lt;weight&gt; &lt;name&gt; &lt;class&gt; [&lt;args&gt;]
* </pre>
* &lt;weight&gt; is a floating point value which is multiplied times the
* benchmark's execution time to determine its weighted score. The
* total score of the benchmark suite is the sum of all weighted scores
* of its benchmarks.
* <p>
* &lt;name&gt; is a name used to identify the benchmark on the benchmark
* report. If the name contains whitespace, the quote character '"' should
* be used as a delimiter.
* <p>
* &lt;class&gt; is the full name (including the package) of the class
* containing the benchmark implementation. This class must implement
* bench.Benchmark.
* <p>
* [&lt;args&gt;] is a variable-length list of runtime arguments to pass to
* the benchmark. Arguments containing whitespace should use the quote
* character '"' as a delimiter.
* <p>
* <b>Example:</b>
* <pre>
* 3.5 "My benchmark" bench.serial.Test first second "third arg"
* </pre>
*/
public Harness(InputStream in) throws IOException, ConfigFormatException {
Vector bvec = new Vector();
StreamTokenizer tokens = new StreamTokenizer(new InputStreamReader(in));
tokens.resetSyntax();
tokens.wordChars(0, 255);
tokens.whitespaceChars(0, ' ');
tokens.commentChar('#');
tokens.quoteChar('"');
tokens.eolIsSignificant(true);
tokens.nextToken();
while (tokens.ttype != StreamTokenizer.TT_EOF) {
switch (tokens.ttype) {
case StreamTokenizer.TT_WORD:
case '"': // parse line
bvec.add(parseBenchInfo(tokens));
break;
default: // ignore
tokens.nextToken();
break;
}
}
binfo = (BenchInfo[]) bvec.toArray(new BenchInfo[bvec.size()]);
}
BenchInfo parseBenchInfo(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
float weight = parseBenchWeight(tokens);
String name = parseBenchName(tokens);
Benchmark bench = parseBenchClass(tokens);
String[] args = parseBenchArgs(tokens);
if (tokens.ttype == StreamTokenizer.TT_EOL)
tokens.nextToken();
return new BenchInfo(bench, name, weight, args);
}
float parseBenchWeight(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
float weight;
switch (tokens.ttype) {
case StreamTokenizer.TT_WORD:
case '"':
try {
weight = Float.parseFloat(tokens.sval);
} catch (NumberFormatException e) {
throw new ConfigFormatException("illegal weight value \"" +
tokens.sval + "\" on line " + tokens.lineno());
}
tokens.nextToken();
return weight;
default:
throw new ConfigFormatException("missing weight value on line "
+ tokens.lineno());
}
}
String parseBenchName(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
String name;
switch (tokens.ttype) {
case StreamTokenizer.TT_WORD:
case '"':
name = tokens.sval;
tokens.nextToken();
return name;
default:
throw new ConfigFormatException("missing benchmark name on " +
"line " + tokens.lineno());
}
}
Benchmark parseBenchClass(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
Benchmark bench;
switch (tokens.ttype) {
case StreamTokenizer.TT_WORD:
case '"':
try {
Class cls = Class.forName(tokens.sval);
bench = (Benchmark) cls.newInstance();
} catch (Exception e) {
throw new ConfigFormatException("unable to instantiate " +
"benchmark \"" + tokens.sval + "\" on line " +
tokens.lineno());
}
tokens.nextToken();
return bench;
default:
throw new ConfigFormatException("missing benchmark class " +
"name on line " + tokens.lineno());
}
}
String[] parseBenchArgs(StreamTokenizer tokens)
throws IOException, ConfigFormatException
{
Vector vec = new Vector();
for (;;) {
switch (tokens.ttype) {
case StreamTokenizer.TT_EOF:
case StreamTokenizer.TT_EOL:
return (String[]) vec.toArray(new String[vec.size()]);
case StreamTokenizer.TT_WORD:
case '"':
vec.add(tokens.sval);
tokens.nextToken();
break;
default:
throw new ConfigFormatException("unrecognized arg token " +
"on line " + tokens.lineno());
}
}
}
/**
* Run benchmarks, writing results to the given reporter.
*/
public void runBenchmarks(Reporter reporter, boolean verbose) {
for (int i = 0; i < binfo.length; i++) {
if (verbose)
System.out.println("Running benchmark " + i + " (" +
binfo[i].getName() + ")");
try {
binfo[i].runBenchmark();
} catch (Exception e) {
System.err.println("Error: benchmark " + i + " failed: " + e);
e.printStackTrace();
}
cleanup();
}
try {
reporter.writeReport(binfo, System.getProperties());
} catch (IOException e) {
System.err.println("Error: failed to write benchmark report");
}
}
/**
* Clean up method that is invoked after the completion of each benchmark.
* The default implementation calls System.gc(); subclasses may override
* this to perform additional cleanup measures.
*/
protected void cleanup() {
System.gc();
}
}

View file

@ -0,0 +1,108 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
/**
* Benchmark html report generator.
*/
public class HtmlReporter implements Reporter {
static final int PRECISION = 3;
static final String[] PROPNAMES = { "os.name", "os.arch", "os.version",
"java.home", "java.vm.version", "java.vm.vendor", "java.vm.name",
"java.compiler", "java.class.path" };
OutputStream out;
String title;
/**
* Create HtmlReporter which writes to the given stream.
*/
public HtmlReporter(OutputStream out, String title) {
this.out = out;
this.title = title;
}
/**
* Generate html report.
*/
public void writeReport(BenchInfo[] binfo, Properties props)
throws IOException
{
PrintStream p = new PrintStream(out);
float total = 0.0f;
p.println("<html>");
p.println("<head>");
p.println("<title>" + title + "</title>");
p.println("</head>");
p.println("<body bgcolor=\"#ffffff\">");
p.println("<h3>" + title + "</h3>");
p.println("<hr>");
p.println("<table border=0>");
for (int i = 0; i < PROPNAMES.length; i++) {
p.println("<tr><td>" + PROPNAMES[i] + ": <td>" +
props.getProperty(PROPNAMES[i]));
}
p.println("</table>");
p.println("<p>");
p.println("<table border=1>");
p.println("<tr><th># <th>Benchmark Name <th>Time (ms) <th>Score");
for (int i = 0; i < binfo.length; i++) {
BenchInfo b = binfo[i];
p.print("<tr><td>" + i + " <td>" + b.getName());
if (b.getTime() != -1) {
float score = b.getTime() * b.getWeight();
total += score;
p.println(" <td>" + b.getTime() + " <td>" +
Util.floatToString(score, PRECISION));
}
else {
p.println(" <td>-- <td>--");
}
}
p.println("<tr><td colspan=3><b>Total score</b> <td><b>" +
Util.floatToString(total, PRECISION) + "</b>");
p.println("</table>");
p.println("<p>");
p.println("<hr>");
p.println("<i>Report generated on " + new Date() + "</i>");
p.println("</body>");
p.println("</html>");
}
}

View file

@ -0,0 +1,49 @@
#
# Copyright (c) 1999, 2024, 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.
#
#
#
#
# Benchmarking harness makefile
#
BUILD_DIR = ..
JAVA_FILES = BenchInfo.java \
Benchmark.java \
ConfigFormatException.java \
Harness.java \
HtmlReporter.java \
Reporter.java \
TextReporter.java \
Util.java \
XmlReporter.java
all: .classes
.classes: $(JAVA_FILES)
javac -d $(BUILD_DIR) $(JAVA_FILES)
touch .classes
clean:
rm -f *.class .classes

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
import java.io.IOException;
import java.util.Properties;
/**
* Objects implementing this interface are used for printing benchmark reports.
*/
public interface Reporter {
/**
* Write benchmark report to the given stream.
*/
void writeReport(BenchInfo[] binfo, Properties props)
throws IOException;
}

View file

@ -0,0 +1,134 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.Properties;
/**
* Benchmark text report generator.
*/
public class TextReporter implements Reporter {
static final int PRECISION = 3;
static final int INDEX_WIDTH = 3;
static final int NAME_WIDTH = 30;
static final int TIME_WIDTH = 10;
static final int SCORE_WIDTH = 10;
static final int PROPNAME_WIDTH = 25;
static final String[] PROPNAMES = { "os.name", "os.arch", "os.version",
"java.home", "java.vm.version", "java.vm.vendor", "java.vm.name",
"java.compiler", "java.class.path" };
OutputStream out;
String title;
/**
* Create TextReporter which writes to the given stream.
*/
public TextReporter(OutputStream out, String title) {
this.out = out;
this.title = title;
}
/**
* Generate text report.
*/
public void writeReport(BenchInfo[] binfo, Properties props)
throws IOException
{
PrintStream p = new PrintStream(out);
float total = 0.0f;
p.println("\n" + title);
p.println(pad('-', title.length()));
p.println("");
for (int i = 0; i < PROPNAMES.length; i++) {
p.println(fit(PROPNAMES[i] + ":", PROPNAME_WIDTH) +
props.getProperty(PROPNAMES[i]));
}
p.println("");
p.println(fit("#", INDEX_WIDTH) + " " +
fit("Benchmark Name", NAME_WIDTH) + " " +
fit("Time (ms)", TIME_WIDTH) + " " +
fit("Score", SCORE_WIDTH));
p.println(pad('-', INDEX_WIDTH + NAME_WIDTH + TIME_WIDTH +
SCORE_WIDTH + 6));
for (int i = 0; i < binfo.length; i++) {
BenchInfo b = binfo[i];
p.print(fit(Integer.toString(i), INDEX_WIDTH) + " ");
p.print(fit(b.getName(), NAME_WIDTH) + " ");
if (b.getTime() != -1) {
float score = b.getTime() * b.getWeight();
total += score;
p.print(fit(Long.toString(b.getTime()), TIME_WIDTH) + " ");
p.println(fit(Util.floatToString(score, PRECISION),
SCORE_WIDTH));
}
else {
p.print(fit("--", TIME_WIDTH) + " ");
p.println(fit("--", SCORE_WIDTH));
}
}
p.println(pad('-', INDEX_WIDTH + NAME_WIDTH + TIME_WIDTH +
SCORE_WIDTH + 6));
p.println(fit("Total score", INDEX_WIDTH + NAME_WIDTH + TIME_WIDTH +
4) + " " + Util.floatToString(total, PRECISION));
p.println("");
p.println("-----");
p.println("Report generated on " + new Date() + "\n");
p.println("");
}
/**
* Extend or truncate string so it fits in the given space.
*/
private static String fit(String s, int len) {
int slen = s.length();
StringBuffer buf = new StringBuffer(s);
buf.setLength(len);
for (int i = slen; i < len; i++)
buf.setCharAt(i, ' ');
return buf.toString();
}
/**
* Return string with given number of chars.
*/
private static String pad(char c, int len) {
char[] buf = new char[len];
Arrays.fill(buf, c);
return new String(buf);
}
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 1999, 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.
*/
/*
*
*/
package bench;
/**
* Utility class.
*/
class Util {
/**
* Convert float to string, with given precision.
*/
static String floatToString(float f, int precision) {
String s = Float.toString(f);
int i = s.lastIndexOf('.');
if (i == -1)
return s;
int end = i + precision + 1;
return (end < s.length()) ? s.substring(0, end) : s;
}
}

View file

@ -0,0 +1,94 @@
/*
* Copyright (c) 2000, 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.
*/
/*
*
*/
package bench;
import java.awt.Toolkit;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.Properties;
/**
* Benchmark XML report generator. Uses XML format used by other JDK
* benchmarks.
*/
public class XmlReporter implements Reporter {
OutputStream out;
String title;
/**
* Create XmlReporter which writes to the given stream.
*/
public XmlReporter(OutputStream out, String title) {
this.out = out;
this.title = title;
}
/**
* Generate text report.
*/
public void writeReport(BenchInfo[] binfo, Properties props)
throws IOException
{
PrintStream p = new PrintStream(out);
p.println("<REPORT>");
p.println("<NAME>" + title + "</NAME>");
p.println("<DATE>" + new Date() + "</DATE>");
p.println("<VERSION>" + props.getProperty("java.version") +
"</VERSION>");
p.println("<VENDOR>" + props.getProperty("java.vendor") + "</VENDOR>");
p.println("<DIRECTORY>" + props.getProperty("java.home") +
"</DIRECTORY>");
String vmName = props.getProperty("java.vm.name");
String vmInfo = props.getProperty("java.vm.info");
String vmString = (vmName != null && vmInfo != null) ?
vmName + " " + vmInfo : "Undefined";
p.println("<VM_INFO>" + vmString + "</VM_INFO>");
p.println("<OS>" + props.getProperty("os.name") +
" version " + props.getProperty("os.version") + "</OS>");
p.println("<BIT_DEPTH>" +
Toolkit.getDefaultToolkit().getColorModel().getPixelSize() +
"</BIT_DEPTH>");
p.println();
p.println("<DATA RUNS=\"" + 1 + "\" TESTS=\"" + binfo.length + "\">");
for (int i = 0; i < binfo.length; i++) {
BenchInfo b = binfo[i];
String score = (b.getTime() != -1) ?
Double.toString(b.getTime() * b.getWeight()) : "-1";
p.println(b.getName() + "\t" + score);
}
p.println("</DATA>");
p.println("</REPORT>");
}
}

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* The RMI benchmark server is a simple compute-engine-like server which allows
* client benchmarks to create/export and unexport objects off of the server,
* or run arbitrary tasks.
*/
public interface BenchServer extends Remote {
/**
* Interface used for creating server-side remote objects.
*/
public interface RemoteObjectFactory extends Serializable {
Remote create() throws RemoteException;
}
/**
* Interface used for server-side tasks.
*/
public interface Task extends Serializable {
Object execute() throws Exception;
}
/**
* Uses the given remote object factory to create a new remote object on
* the server side.
*/
Remote create(RemoteObjectFactory factory) throws RemoteException;
/**
* Unexports the specified remote object. Returns true if successful,
* false otherwise.
*/
boolean unexport(Remote obj, boolean force) throws RemoteException;
/**
* Execute given task.
*/
Object execute(Task task) throws Exception;
/**
* Invoke the garbage collector.
*/
void gc() throws RemoteException;
/**
* Terminate the server.
*/
void terminate(int delay) throws RemoteException;
}

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import java.lang.ref.WeakReference;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.RemoteObject;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
/**
* Benchmark server implementation.
*/
public class BenchServerImpl
extends UnicastRemoteObject implements BenchServer
{
HashMap implTable = new HashMap();
/**
* Create new server.
*/
public BenchServerImpl() throws RemoteException {
}
/**
* Uses the given remote object factory to create a new remote object on
* the server side.
*/
public Remote create(BenchServer.RemoteObjectFactory factory)
throws RemoteException
{
Remote impl = factory.create();
implTable.put(RemoteObject.toStub(impl), new WeakReference(impl));
return impl;
}
/**
* Unexports the specified remote object. Returns true if successful,
* false otherwise.
*/
public boolean unexport(Remote obj, boolean force) throws RemoteException {
WeakReference iref = (WeakReference) implTable.get(obj);
if (iref == null)
return false;
Remote impl = (Remote) iref.get();
if (impl == null)
return false;
return UnicastRemoteObject.unexportObject(impl, force);
}
/**
* Execute given task.
*/
public Object execute(BenchServer.Task task) throws Exception {
return task.execute();
}
/**
* Invoke the garbage collector.
*/
public void gc() throws RemoteException {
System.gc();
}
/**
* Terminate the server.
*/
public void terminate(int delay) throws RemoteException {
System.exit(0);
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with boolean array arguments and
* return values.
*/
public class BooleanArrayCalls implements Benchmark {
interface Server extends Remote {
public boolean[] call(boolean[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public boolean[] call(boolean[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue boolean array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
boolean[] array = new boolean[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with boolean arguments/return values.
*/
public class BooleanCalls implements Benchmark {
interface Server extends Remote {
public boolean call(boolean val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public boolean call(boolean val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue boolean calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call(true);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with byte array arguments and
* return values.
*/
public class ByteArrayCalls implements Benchmark {
interface Server extends Remote {
public byte[] call(byte[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public byte[] call(byte[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue byte array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
byte[] array = new byte[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with byte arguments/return values.
*/
public class ByteCalls implements Benchmark {
interface Server extends Remote {
public byte call(byte val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public byte call(byte val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue byte calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call((byte) 0);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with char array arguments and
* return values.
*/
public class CharArrayCalls implements Benchmark {
interface Server extends Remote {
public char[] call(char[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public char[] call(char[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue char array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
char[] array = new char[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with char arguments/return values.
*/
public class CharCalls implements Benchmark {
interface Server extends Remote {
public char call(char val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public char call(char val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue char calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call('0');
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.server.RMIClassLoader;
import java.security.CodeSource;
/**
* Benchmark for testing speed of repeated loading of a class not found in
* classpath.
*/
public class ClassLoading implements Benchmark {
static final String ALTROOT = "!/bench/rmi/altroot/";
static final String CLASSNAME = "Node";
/**
* Repeatedly load a class not found in classpath through RMIClassLoader.
* Arguments: <# reps>
*/
public long run(String[] args) throws Exception {
int reps = Integer.parseInt(args[0]);
CodeSource csrc = getClass().getProtectionDomain().getCodeSource();
String url = "jar:" + csrc.getLocation().toString() + ALTROOT;
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
RMIClassLoader.loadClass(url, CLASSNAME);
long time = System.currentTimeMillis() - start;
return time;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with double array arguments and
* return values.
*/
public class DoubleArrayCalls implements Benchmark {
interface Server extends Remote {
public double[] call(double[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public double[] call(double[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue double array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
double[] array = new double[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with double arguments/return values.
*/
public class DoubleCalls implements Benchmark {
interface Server extends Remote {
public double call(double val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public double call(double val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue double calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call(0.0);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls which throw exceptions.
*/
public class ExceptionCalls implements Benchmark {
static class FooException extends Exception {
}
interface Server extends Remote {
public void call() throws RemoteException, FooException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public void call() throws RemoteException, FooException {
throw new FooException();
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue calls which throw exceptions.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int reps = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++) {
try {
stub.call();
} catch (FooException e) {}
}
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of UnicastRemoteObject.exportObject().
*/
public class ExportObjs implements Benchmark {
static class RemoteObj implements Remote {
}
/**
* Export remote objects.
* Arguments: <# objects>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
Remote[] objs = new Remote[size];
for (int i = 0; i < size; i++)
objs[i] = new RemoteObj();
long start = System.currentTimeMillis();
for (int i = 0; i < size; i++)
UnicastRemoteObject.exportObject(objs[i],0);
long time = System.currentTimeMillis() - start;
for (int i = 0; i < size; i++)
UnicastRemoteObject.unexportObject(objs[i], true);
return time;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with float array arguments and
* return values.
*/
public class FloatArrayCalls implements Benchmark {
interface Server extends Remote {
public float[] call(float[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public float[] call(float[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue float array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
float[] array = new float[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with float arguments/return values.
*/
public class FloatCalls implements Benchmark {
interface Server extends Remote {
public float call(float val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public float call(float val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue float calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call((float) 0.0);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with int array arguments and
* return values.
*/
public class IntArrayCalls implements Benchmark {
interface Server extends Remote {
public int[] call(int[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public int[] call(int[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue int array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
int[] array = new int[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with int arguments/return values.
*/
public class IntCalls implements Benchmark {
interface Server extends Remote {
public int call(int val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public int call(int val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue int calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call(0);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with long array arguments and
* return values.
*/
public class LongArrayCalls implements Benchmark {
interface Server extends Remote {
public long[] call(long[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public long[] call(long[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue long array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long[] array = new long[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with long arguments/return values.
*/
public class LongCalls implements Benchmark {
interface Server extends Remote {
public long call(long val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public long call(long val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue long calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call(0L);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,527 @@
/*
* Copyright (c) 2000, 2024, 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
* @summary The RMI benchmark test. This java class is used to run the test
* under JTREG.
* @library ../../../../testlibrary ../../ /test/lib
* @modules java.desktop
* java.rmi/sun.rmi.registry
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary bench.BenchInfo bench.HtmlReporter bench.Util jdk.test.lib.process.ProcessTools
* bench.Benchmark bench.Reporter bench.XmlReporter bench.ConfigFormatException
* bench.Harness bench.TextReporter bench.rmi.BenchServer
* bench.rmi.DoubleArrayCalls bench.rmi.LongCalls bench.rmi.ShortCalls
* bench.rmi.BenchServerImpl bench.rmi.DoubleCalls bench.rmi.Main
* bench.rmi.SmallObjTreeCalls bench.rmi.BooleanArrayCalls
* bench.rmi.ExceptionCalls bench.rmi.NullCalls bench.rmi.BooleanCalls
* bench.rmi.ExportObjs bench.rmi.ObjArrayCalls bench.rmi.ByteArrayCalls
* bench.rmi.FloatArrayCalls bench.rmi.ObjTreeCalls bench.rmi.ByteCalls
* bench.rmi.FloatCalls bench.rmi.ProxyArrayCalls bench.rmi.CharArrayCalls
* bench.rmi.IntArrayCalls bench.rmi.RemoteObjArrayCalls bench.rmi.CharCalls
* bench.rmi.IntCalls bench.rmi.ClassLoading bench.rmi.LongArrayCalls
* bench.rmi.ShortArrayCalls
* bench.rmi.altroot.Node
* @run main/othervm/timeout=1800 bench.rmi.Main -server -c config
* @author Mike Warres, Nigel Daley
*/
package bench.rmi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RemoteObject;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import bench.ConfigFormatException;
import bench.Harness;
import bench.HtmlReporter;
import bench.Reporter;
import bench.TextReporter;
import bench.XmlReporter;
import static bench.rmi.Main.OutputFormat.HTML;
import static bench.rmi.Main.OutputFormat.TEXT;
import static bench.rmi.Main.OutputFormat.XML;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
/**
* RMI/Serialization benchmark tests.
*/
public class Main {
/**
* RMI-specific benchmark harness.
*/
static class RMIHarness extends Harness {
/**
* Construct new RMI benchmark harness.
*/
RMIHarness(InputStream in) throws IOException, ConfigFormatException {
super(in);
}
/**
* Cleanup both client and server side in between each benchmark.
*/
@Override
protected void cleanup() {
System.gc();
if (Main.runmode == CLIENT) {
try {
Main.server.gc();
} catch (RemoteException e) {
System.err.println("Warning: server gc failed: " + e);
}
}
}
}
static final String CONFFILE = "config";
static final String VERSION = "1.3";
static final String REGNAME = "server";
static final int SAMEVM = 0;
static final int CLIENT = 1;
static final int SERVER = 2;
static enum OutputFormat {
TEXT {
@Override
Reporter getReport(String title) {
return new TextReporter(repstr, title);
}
},
HTML {
@Override
Reporter getReport(String title) {
return new HtmlReporter(repstr, title);
}
},
XML {
@Override
Reporter getReport(String title) {
return new XmlReporter(repstr, title);
}
};
abstract Reporter getReport(String title);
};
static final String TEST_SRC_PATH = System.getProperty("test.src") + File.separator;
static boolean verbose;
static boolean list;
static boolean exitOnTimer;
static int testDurationSeconds;
static volatile boolean exitRequested;
static Timer timer;
static OutputFormat format = TEXT;
static int runmode;
static String confFile;
static InputStream confstr;
static String repFile;
static OutputStream repstr;
static String host;
static int port;
static RMIHarness harness;
static Reporter reporter;
static BenchServer server;
static BenchServerImpl serverImpl;
/**
* Returns reference to benchmark server.
*
* @return a benchmark server
*/
public static BenchServer getBenchServer() {
return server;
}
/**
* Prints help message.
*/
static void usage() {
PrintStream p = System.err;
p.println("\nUsage: java -jar rmibench.jar [-options]");
p.println("\nwhere options are:");
p.println(" -h print this message");
p.println(" -v verbose mode");
p.println(" -l list configuration file");
p.println(" -t <num hours> repeat benchmarks for specified number of hours");
p.println(" -o <file> specify output file");
p.println(" -c <file> specify (non-default) "
+ "configuration file");
p.println(" -html format output as html "
+ "(default is text)");
p.println(" -xml format output as xml");
p.println(" -server run benchmark server ");
p.println(" -client <host:port> run benchmark client using server "
+ "on specified host/port");
}
/**
* Throw RuntimeException that wrap message.
*
* @param mesg a message will be wrapped in the RuntimeException.
*/
static void die(String mesg) {
throw new RuntimeException(mesg);
}
/**
* Benchmark mainline.
*
* @param args
*/
public static void main(String[] args) {
parseArgs(args);
setupStreams();
if (list) {
listConfig();
} else {
setupServer();
switch (runmode) {
case SAMEVM:
case CLIENT:
setupHarness();
setupReporter();
if (exitOnTimer) {
setupTimer(testDurationSeconds);
do {
runBenchmarks();
} while (!exitRequested);
} else {
runBenchmarks();
}
break;
case SERVER:
//Setup for client mode, server will fork client process
//after its initiation.
List<String> clientProcessStr = new ArrayList<>();
clientProcessStr.add("-Dtest.src=" + TEST_SRC_PATH);
clientProcessStr.add("bench.rmi.Main"); //Client mode
if (verbose) {
clientProcessStr.add("-v");
}
if (list) {
clientProcessStr.add("-l");
}
clientProcessStr.add("-client");
clientProcessStr.add("localhost:" + port);
if (exitOnTimer) {
clientProcessStr.add("-t");
clientProcessStr.add(String.valueOf(testDurationSeconds / 3600));
}
if (repFile != null) {
clientProcessStr.add("-o");
clientProcessStr.add(repFile);
}
if (confFile != null) {
clientProcessStr.add("-c");
clientProcessStr.add(confFile);
}
switch (format) {
case HTML:
clientProcessStr.add("-html");
break;
case XML:
clientProcessStr.add("-xml");
break;
}
try {
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(clientProcessStr);
OutputAnalyzer outputAnalyzer = ProcessTools.executeProcess(pb);
System.out.println(outputAnalyzer.getOutput());
outputAnalyzer.shouldHaveExitValue(0);
} catch (IOException ex) {
die("Error: Unable start client process, ex=" + ex.getMessage());
} catch (Exception ex) {
die("Error: Error happening to client process, ex=" + ex.getMessage());
}
break;
}
}
}
/**
* Parse command-line arguments.
*/
static void parseArgs(String[] args) {
for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "-h":
usage();
System.exit(0);
break;
case "-v":
verbose = true;
break;
case "-l":
list = true;
break;
case "-t":
if (++i >= args.length) {
die("Error: no timeout value specified");
}
try {
exitOnTimer = true;
testDurationSeconds = Integer.parseInt(args[i]) * 3600;
} catch (NumberFormatException e) {
die("Error: unable to determine timeout value");
}
break;
case "-o":
if (++i >= args.length) {
die("Error: no output file specified");
}
try {
repFile = args[i];
repstr = new FileOutputStream(repFile);
} catch (FileNotFoundException e) {
die("Error: unable to open \"" + args[i] + "\"");
}
break;
case "-c":
if (++i >= args.length) {
die("Error: no config file specified");
}
confFile = args[i];
String confFullPath = TEST_SRC_PATH + confFile;
try {
confstr = new FileInputStream(confFullPath);
} catch (FileNotFoundException e) {
die("Error: unable to open \"" + confFullPath + "\"");
}
break;
case "-html":
if (format != TEXT) {
die("Error: conflicting formats");
}
format = HTML;
break;
case "-xml":
if (format != TEXT) {
die("Error: conflicting formats");
}
format = XML;
break;
case "-client":
if (runmode == CLIENT) {
die("Error: multiple -client options");
}
if (runmode == SERVER) {
die("Error: -client and -server options conflict");
}
if (++i >= args.length) {
die("Error: -client missing host/port");
}
try {
String[] hostAndPort = args[i].split(":");
if (hostAndPort.length != 2) {
die("Error: Invalid format host/port:" + args[i]);
}
host = hostAndPort[0];
port = Integer.parseInt(hostAndPort[1]);
} catch (NumberFormatException e) {
die("Error: illegal host/port specified for -client");
}
runmode = CLIENT;
break;
case "-server":
if (runmode == CLIENT) {
die("Error: -client and -server options conflict");
}
if (runmode == SERVER) {
die("Error: multiple -server options");
}
try {
//This is the hack code because named package class has
//difficulty in accessing unnamed package class. This
//should be removed ater JDK-8003358 is finished.
port = (int) Class.forName("TestLibrary")
.getMethod("getUnusedRandomPort")
.invoke(null);
} catch (ReflectiveOperationException ex) {
die("Error: can't get a free port " + ex);
}
runmode = SERVER;
break;
default:
usage();
die("Illegal option: \"" + args[i] + "\"");
}
}
}
/**
* Set up configuration file and report streams, if not set already.
*/
static void setupStreams() {
if (repstr == null) {
repstr = System.out;
}
if (confstr == null) {
confstr = Main.class.getResourceAsStream(TEST_SRC_PATH + CONFFILE);
}
if (confstr == null) {
die("Error: unable to find default config file");
}
}
/**
* Print contents of configuration file to selected output stream.
*/
static void listConfig() {
try {
byte[] buf = new byte[256];
int len;
while ((len = confstr.read(buf)) != -1)
repstr.write(buf, 0, len);
} catch (IOException e) {
die("Error: failed to list config file");
}
}
/**
* Setup benchmark server.
*/
static void setupServer() {
switch (runmode) {
case SAMEVM:
try {
serverImpl = new BenchServerImpl();
server = (BenchServer) RemoteObject.toStub(serverImpl);
} catch (RemoteException e) {
die("Error: failed to create local server: " + e);
}
if (verbose)
System.out.println("Benchmark server created locally");
break;
case CLIENT:
try {
Registry reg = LocateRegistry.getRegistry(host, port);
server = (BenchServer) reg.lookup(REGNAME);
} catch (NotBoundException | RemoteException e) {
die("Error: failed to connect to server: " + e);
}
if (server == null) {
die("Error: server not found");
}
if (verbose) {
System.out.println("Connected to benchmark server on " +
host + ":" + port);
}
break;
case SERVER:
try {
Registry reg = LocateRegistry.createRegistry(port);
serverImpl = new BenchServerImpl();
reg.bind(REGNAME, serverImpl);
} catch (AlreadyBoundException | RemoteException e) {
die("Error: failed to initialize server: " + e);
}
if (verbose) {
System.out.println("Benchmark server started on port " +
port);
}
break;
default:
throw new InternalError("illegal runmode");
}
}
/**
* Set up the timer to end the test.
*
* @param delay the amount of delay, in seconds, before requesting the
* process exit
*/
static void setupTimer(int delay) {
timer = new Timer(true);
timer.schedule(
new TimerTask() {
@Override
public void run() {
exitRequested = true;
}
},
delay * 1000);
}
/**
* Set up benchmark harness.
*/
static void setupHarness() {
try {
harness = new RMIHarness(confstr);
} catch (ConfigFormatException e) {
String errmsg = e.getMessage();
if (errmsg != null) {
die("Error parsing config file: " + errmsg);
} else {
die("Error: illegal config file syntax");
}
} catch (IOException e) {
die("Error: failed to read config file");
}
}
/**
* Setup benchmark reporter.
*/
static void setupReporter() {
reporter = format.getReport("RMI Benchmark, v" + VERSION);
}
/**
* Run benchmarks.
*/
static void runBenchmarks() {
harness.runBenchmarks(reporter, verbose);
}
}

View file

@ -0,0 +1,74 @@
#
# Copyright (c) 2000, 2024, 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.
#
#
#
#
# RMI benchmarks makefile
#
BUILD_DIR = ../..
JAVA_FILES = BenchServer.java \
BenchServerImpl.java \
BooleanArrayCalls.java \
BooleanCalls.java \
ByteArrayCalls.java \
ByteCalls.java \
CharArrayCalls.java \
CharCalls.java \
ClassLoading.java \
DoubleArrayCalls.java \
DoubleCalls.java \
ExceptionCalls.java \
ExportObjs.java \
FloatArrayCalls.java \
FloatCalls.java \
IntArrayCalls.java \
IntCalls.java \
LongArrayCalls.java \
LongCalls.java \
Main.java \
NullCalls.java \
ObjArrayCalls.java \
ObjTreeCalls.java \
ProxyArrayCalls.java \
RemoteObjArrayCalls.java \
ShortArrayCalls.java \
ShortCalls.java \
SmallObjTreeCalls.java \
TheTerminator.java
all: .classes altroot.dir
.classes: $(JAVA_FILES)
javac -d $(BUILD_DIR) $(JAVA_FILES)
touch .classes
altroot.dir:
cd altroot ; $(MAKE)
altroot.clean:
cd altroot ; $(MAKE) clean
clean: altroot.clean
rm -f *.class .classes

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of null calls.
*/
public class NullCalls implements Benchmark {
interface Server extends Remote {
public void call() throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public void call() throws RemoteException {
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue null calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int reps = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call();
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,103 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with object array parameters and return
* values.
*/
public class ObjArrayCalls implements Benchmark {
static class Node implements Serializable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
}
interface Server extends Remote {
public Node[] call(Node[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public Node[] call(Node[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue calls using arrays of objects as parameters/return values.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
Node[] nodes = new Node[size];
for (int i = 0; i < size; i++)
nodes[i] = new Node(null, 0);
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(nodes);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,101 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with object tree parameters and return
* values.
*/
public class ObjTreeCalls implements Benchmark {
static class Node implements Serializable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
}
interface Server extends Remote {
public Node call(Node val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public Node call(Node val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue calls using trees of objects as parameters/return values.
* Arguments: <tree depth> <# calls>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
Node node = new Node(null, depth);
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(node);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,114 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with proxy array parameters and return
* values.
*/
public class ProxyArrayCalls implements Benchmark {
static class DummyHandler implements InvocationHandler, Serializable {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
return null;
}
}
public static interface DummyInterface {
public void foo();
}
interface Server extends Remote {
public Proxy[] call(Proxy[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public Proxy[] call(Proxy[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Generate proxy object array of the given size.
*/
Proxy[] genProxies(int size) throws Exception {
Class proxyClass =
Proxy.getProxyClass(DummyInterface.class.getClassLoader(),
new Class[] { DummyInterface.class });
Constructor proxyCons =
proxyClass.getConstructor(new Class[] { InvocationHandler.class });
Object[] consArgs = new Object[] { new DummyHandler() };
Proxy[] proxies = new Proxy[size];
for (int i = 0; i < size; i++)
proxies[i] = (Proxy) proxyCons.newInstance(consArgs);
return proxies;
}
/**
* Issue calls using arrays of proxies as parameters/return values.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
Proxy[] proxies = genProxies(size);
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(proxies);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with remote object array parameters and
* return values.
*/
public class RemoteObjArrayCalls implements Benchmark {
static class RemoteObj extends UnicastRemoteObject implements Remote {
RemoteObj() throws RemoteException {
}
}
interface Server extends Remote {
public Remote[] call(Remote[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public Remote[] call(Remote[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue calls using arrays of remote objects as parameters/return values.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
Remote[] objs = new Remote[size];
for (int i = 0; i < size; i++)
objs[i] = new RemoteObj();
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(objs);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with short array arguments and
* return values.
*/
public class ShortArrayCalls implements Benchmark {
interface Server extends Remote {
public short[] call(short[] a) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public short[] call(short[] a) throws RemoteException {
return a;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue short array calls.
* Arguments: <array size> <# calls>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
short[] array = new short[size];
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(array);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with short arguments/return values.
*/
public class ShortCalls implements Benchmark {
interface Server extends Remote {
public short call(short val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public short call(short val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue short calls.
* Arguments: <# calls>
*/
public long run(String[] args) throws Exception {
int cycles = Integer.parseInt(args[0]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
long start = System.currentTimeMillis();
for (int i = 0; i < cycles; i++)
stub.call((short) 0);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,92 @@
/*
* Copyright (c) 2000, 2008, 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.
*/
/*
*
*/
package bench.rmi;
import bench.Benchmark;
import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* Benchmark for testing speed of calls with small object tree parameters and
* return values.
*/
public class SmallObjTreeCalls implements Benchmark {
static class Node implements Serializable {
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
}
interface Server extends Remote {
public Node call(Node val) throws RemoteException;
}
static class ServerImpl extends UnicastRemoteObject implements Server {
public ServerImpl() throws RemoteException {
}
public Node call(Node val) throws RemoteException {
return val;
}
}
static class ServerFactory implements BenchServer.RemoteObjectFactory {
public Remote create() throws RemoteException {
return new ServerImpl();
}
}
/**
* Issue calls using trees of small objects as parameters/return values.
* Arguments: <tree depth> <# calls>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int reps = Integer.parseInt(args[1]);
BenchServer bsrv = Main.getBenchServer();
Server stub = (Server) bsrv.create(new ServerFactory());
Node node = new Node(null, depth);
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++)
stub.call(node);
long time = System.currentTimeMillis() - start;
bsrv.unexport(stub, true);
return time;
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2000, 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.io.Serializable;
public class Node implements Serializable {
}

View file

@ -0,0 +1,111 @@
#
# Configuration file for rmi benchmarks
#
# Warmup (null calls)
# Arguments: <# calls>
0.0 "Warmup" bench.rmi.NullCalls 50000
# Time null calls
# Arguments: <# calls>
1.0 "Null calls" bench.rmi.NullCalls 10000
# Time boolean calls
# Arguments: <# calls>
1.0 "Boolean calls" bench.rmi.BooleanCalls 10000
# Time byte calls
# Arguments: <# calls>
1.0 "Byte calls" bench.rmi.ByteCalls 10000
# Time char calls
# Arguments: <# calls>
1.0 "Char calls" bench.rmi.CharCalls 10000
# Time short calls
# Arguments: <# calls>
1.0 "Short calls" bench.rmi.ShortCalls 10000
# Time int calls
# Arguments: <# calls>
1.0 "Int calls" bench.rmi.IntCalls 10000
# Time long calls
# Arguments: <# calls>
1.0 "Long calls" bench.rmi.LongCalls 10000
# Time float calls
# Arguments: <# calls>
1.0 "Float calls" bench.rmi.FloatCalls 10000
# Time double calls
# Arguments: <# calls>
1.0 "Double calls" bench.rmi.DoubleCalls 10000
# Time boolean array calls
# Arguments: <array size> <# calls>
1.0 "Boolean array calls" bench.rmi.BooleanArrayCalls 100 10000
# Time byte array calls
# Arguments: <array size> <# calls>
1.0 "Byte array calls" bench.rmi.ByteArrayCalls 100 10000
# Time char array calls
# Arguments: <array size> <# calls>
1.0 "Char array calls" bench.rmi.CharArrayCalls 100 10000
# Time short array calls
# Arguments: <array size> <# calls>
1.0 "Short array calls" bench.rmi.ShortArrayCalls 100 10000
# Time int array calls
# Arguments: <array size> <# calls>
1.0 "Int array calls" bench.rmi.IntArrayCalls 100 10000
# Time long array calls
# Arguments: <array size> <# calls>
1.0 "Long array calls" bench.rmi.LongArrayCalls 100 10000
# Time float array calls
# Arguments: <array size> <# calls>
1.0 "Float array calls" bench.rmi.FloatArrayCalls 100 10000
# Time double array calls
# Arguments: <array size> <# calls>
1.0 "Double array calls" bench.rmi.DoubleArrayCalls 100 10000
# Time small-object tree calls
# Arguments: <tree depth> <# calls>
1.0 "Small object tree calls" bench.rmi.SmallObjTreeCalls 4 10000
# Time object tree calls
# Arguments: <tree depth> <# calls>
1.0 "Object tree calls" bench.rmi.ObjTreeCalls 4 10000
# Time object array calls
# Arguments: <array size> <# calls>
1.0 "Object array calls" bench.rmi.ObjArrayCalls 100 10000
# Time remote object array calls
# Arguments: <array size> <# calls>
1.0 "Remote object array calls" bench.rmi.RemoteObjArrayCalls 100 10000
# Time proxy object array calls
# Arguments: <array size> <# calls>
#
# NOTE: this benchmark should be commented out unless you are running Java 2
# version 1.3 or higher
# 1.0 "Proxy array calls" bench.rmi.ProxyArrayCalls 100 10000
# Time exception calls
# Arguments: <# calls>
1.0 "Exception calls" bench.rmi.ExceptionCalls 10000
# Time exporting objects
# Arguments: <# objects>
1.0 "Exporting objects" bench.rmi.ExportObjs 10000
# Time class loading
# Arguments: <# reps>
1.0 "Class loading" bench.rmi.ClassLoading 10000

View file

@ -0,0 +1 @@
Main-Class: bench.rmi.Main

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of boolean array reads/writes.
*/
public class BooleanArrays implements Benchmark {
/**
* Write and read boolean arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
boolean[][] arrays = new boolean[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, boolean[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of boolean reads/writes.
*/
public class Booleans implements Benchmark {
/**
* Write and read boolean values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeBoolean(false);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readBoolean();
}
}
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of byte array reads/writes.
*/
public class ByteArrays implements Benchmark {
/**
* Write and read byte arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
byte[][] arrays = new byte[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, byte[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of byte reads/writes.
*/
public class Bytes implements Benchmark {
/**
* Write and read byte values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeByte(0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readByte();
}
}
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of char array reads/writes.
*/
public class CharArrays implements Benchmark {
/**
* Write and read char arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
char[][] arrays = new char[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, char[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of char reads/writes.
*/
public class Chars implements Benchmark {
/**
* Write and read char values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeChar('0');
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readChar();
}
}
}
}

View file

@ -0,0 +1,128 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
/**
* Benchmark for testing speed of class descriptor reads/writes.
*/
public class ClassDesc implements Benchmark {
static class Dummy0 implements Serializable { Dummy0 i0; }
static class Dummy1 extends Dummy0 { Dummy1 i1; }
static class Dummy2 extends Dummy1 { Dummy2 i2; }
static class Dummy3 extends Dummy2 { Dummy3 i3; }
static class Dummy4 extends Dummy3 { Dummy4 i4; }
static class Dummy5 extends Dummy4 { Dummy5 i5; }
static class Dummy6 extends Dummy5 { Dummy6 i6; }
static class Dummy7 extends Dummy6 { Dummy7 i7; }
static class Dummy8 extends Dummy7 { Dummy8 i8; }
static class Dummy9 extends Dummy8 { Dummy9 i9; }
static class Dummy10 extends Dummy9 { Dummy10 i10; }
static class Dummy11 extends Dummy10 { Dummy11 i11; }
static class Dummy12 extends Dummy11 { Dummy12 i12; }
static class Dummy13 extends Dummy12 { Dummy13 i13; }
static class Dummy14 extends Dummy13 { Dummy14 i14; }
static class Dummy15 extends Dummy14 { Dummy15 i15; }
static class Dummy16 extends Dummy15 { Dummy16 i16; }
static class Dummy17 extends Dummy16 { Dummy17 i17; }
static class Dummy18 extends Dummy17 { Dummy18 i18; }
static class Dummy19 extends Dummy18 { Dummy19 i19; }
static class Dummy20 extends Dummy19 { Dummy20 i20; }
static class Dummy21 extends Dummy20 { Dummy21 i21; }
static class Dummy22 extends Dummy21 { Dummy22 i22; }
static class Dummy23 extends Dummy22 { Dummy23 i23; }
static class Dummy24 extends Dummy23 { Dummy24 i24; }
static class Dummy25 extends Dummy24 { Dummy25 i25; }
static class Dummy26 extends Dummy25 { Dummy26 i26; }
static class Dummy27 extends Dummy26 { Dummy27 i27; }
static class Dummy28 extends Dummy27 { Dummy28 i28; }
static class Dummy29 extends Dummy28 { Dummy29 i29; }
static class Dummy30 extends Dummy29 { Dummy30 i30; }
static class Dummy31 extends Dummy30 { Dummy31 i31; }
static class Dummy32 extends Dummy31 { Dummy32 i32; }
static class Dummy33 extends Dummy32 { Dummy33 i33; }
static class Dummy34 extends Dummy33 { Dummy34 i34; }
static class Dummy35 extends Dummy34 { Dummy35 i35; }
static class Dummy36 extends Dummy35 { Dummy36 i36; }
static class Dummy37 extends Dummy36 { Dummy37 i37; }
static class Dummy38 extends Dummy37 { Dummy38 i38; }
static class Dummy39 extends Dummy38 { Dummy39 i39; }
static class Dummy40 extends Dummy39 { Dummy40 i40; }
static class Dummy41 extends Dummy40 { Dummy41 i41; }
static class Dummy42 extends Dummy41 { Dummy42 i42; }
static class Dummy43 extends Dummy42 { Dummy43 i43; }
static class Dummy44 extends Dummy43 { Dummy44 i44; }
static class Dummy45 extends Dummy44 { Dummy45 i45; }
static class Dummy46 extends Dummy45 { Dummy46 i46; }
static class Dummy47 extends Dummy46 { Dummy47 i47; }
static class Dummy48 extends Dummy47 { Dummy48 i48; }
static class Dummy49 extends Dummy48 { Dummy49 i49; }
static class Dummy50 extends Dummy49 { Dummy50 i50; }
/**
* Write and read class descriptors to/from a stream.
* Arguments: <# cycles>
*/
public long run(String[] args) throws Exception {
int ncycles = Integer.parseInt(args[0]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
ObjectStreamClass desc = ObjectStreamClass.lookup(Dummy50.class);
doReps(oout, oin, sbuf, desc, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, desc, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, ObjectStreamClass desc, int ncycles)
throws Exception
{
for (int i = 0; i < ncycles; i++) {
sbuf.reset();
oout.reset();
oout.writeObject(desc);
oout.flush();
oin.readObject();
}
}
}

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of ObjectOutputStream/ObjectInputStream
* construction.
*/
public class Cons implements Benchmark {
/**
* Dummy object to write to newly constructed serialization stream.
*/
static class Dummy implements Serializable {
}
/**
* Repeatedly construct ObjectOutputStream and ObjectInputStream objects.
* Arguments: <# repetitions>
*/
public long run(String[] args) throws Exception {
int reps = Integer.parseInt(args[0]);
Dummy dummy = new Dummy();
StreamBuffer sbuf = new StreamBuffer();
doReps(sbuf, dummy, 1); // warmup
long start = System.currentTimeMillis();
doReps(sbuf, dummy, reps);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of cycles.
*/
void doReps(StreamBuffer sbuf, Dummy dummy, int reps) throws Exception {
OutputStream out = sbuf.getOutputStream();
InputStream in = sbuf.getInputStream();
for (int i = 0; i < reps; i++) {
sbuf.reset();
ObjectOutputStream oout = new ObjectOutputStream(out);
oout.writeObject(dummy);
oout.flush();
ObjectInputStream oin = new ObjectInputStream(in);
oin.readObject();
}
}
}

View file

@ -0,0 +1,131 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of writes and reads of an object tree, where
* nodes contain custom writeObject() and readObject() methods that call
* defaultWriteObject() and defaultReadObject().
*/
public class CustomDefaultObjTrees implements Benchmark {
static class Node implements Serializable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
}
}
/**
* Write and read a tree of objects from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <tree depth> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[] trees = genTrees(depth, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, trees, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, trees, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object trees.
*/
Node[] genTrees(int depth, int ntrees) {
Node[] trees = new Node[ntrees];
for (int i = 0; i < ntrees; i++) {
trees[i] = new Node(null, depth);
}
return trees;
}
/**
* Run benchmark for given number of batches, with each batch containing
* the given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,152 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of writes and reads of an object tree, where
* nodes contain custom writeObject() and readObject() methods.
*/
public class CustomObjTrees implements Benchmark {
static class Node implements Serializable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeBoolean(z);
out.writeByte(b);
out.writeChar(c);
out.writeShort(s);
out.writeInt(i);
out.writeFloat(f);
out.writeLong(j);
out.writeDouble(d);
out.writeObject(str);
out.writeObject(parent);
out.writeObject(left);
out.writeObject(right);
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
z = in.readBoolean();
b = in.readByte();
c = in.readChar();
s = in.readShort();
i = in.readInt();
f = in.readFloat();
j = in.readLong();
d = in.readDouble();
str = (String) in.readObject();
parent = in.readObject();
left = in.readObject();
right = in.readObject();
}
}
/**
* Write and read a tree of objects from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <tree depth> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[] trees = genTrees(depth, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, trees, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, trees, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object trees.
*/
Node[] genTrees(int depth, int ntrees) {
Node[] trees = new Node[ntrees];
for (int i = 0; i < ntrees; i++) {
trees[i] = new Node(null, depth);
}
return trees;
}
/**
* Run benchmark for given number of batches, with each batch containing
* the given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of double array reads/writes.
*/
public class DoubleArrays implements Benchmark {
/**
* Write and read double arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
double[][] arrays = new double[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, double[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of double reads/writes.
*/
public class Doubles implements Benchmark {
/**
* Write and read double values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeDouble(0.0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readDouble();
}
}
}
}

View file

@ -0,0 +1,157 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of writes and reads of a tree of Externalizable
* objects.
*/
public class ExternObjTrees implements Benchmark {
static class Node implements Externalizable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
public Node() {
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeBoolean(z);
out.writeByte(b);
out.writeChar(c);
out.writeShort(s);
out.writeInt(i);
out.writeFloat(f);
out.writeLong(j);
out.writeDouble(d);
out.writeObject(str);
out.writeObject(parent);
out.writeObject(left);
out.writeObject(right);
}
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
z = in.readBoolean();
b = in.readByte();
c = in.readChar();
s = in.readShort();
i = in.readInt();
f = in.readFloat();
j = in.readLong();
d = in.readDouble();
str = (String) in.readObject();
parent = in.readObject();
left = in.readObject();
right = in.readObject();
}
}
/**
* Write and read a tree of externalizable objects from a stream. The
* benchmark is run in batches: each "batch" consists of a fixed number of
* read/write cycles, and the stream is flushed (and underlying stream
* buffer cleared) in between each batch.
* Arguments: <tree depth> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[] trees = genTrees(depth, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, trees, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, trees, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object trees.
*/
Node[] genTrees(int depth, int ntrees) {
Node[] trees = new Node[ntrees];
for (int i = 0; i < ntrees; i++) {
trees[i] = new Node(null, depth);
}
return trees;
}
/**
* Run benchmark for given number of batches, with each batch containing
* the given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of float array reads/writes.
*/
public class FloatArrays implements Benchmark {
/**
* Write and read float arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
float[][] arrays = new float[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, float[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of float reads/writes.
*/
public class Floats implements Benchmark {
/**
* Write and read float values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeFloat((float) 0.0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readFloat();
}
}
}
}

View file

@ -0,0 +1,156 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of writes and reads of an object tree, where
* nodes contain explicit writeObject() and readObject() methods which use the
* GetField()/PutField() API.
*/
public class GetPutFieldTrees implements Benchmark {
static class Node implements Serializable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
ObjectOutputStream.PutField fields = out.putFields();
fields.put("z", z);
fields.put("b", b);
fields.put("c", c);
fields.put("s", s);
fields.put("i", i);
fields.put("f", f);
fields.put("j", j);
fields.put("d", d);
fields.put("str", str);
fields.put("parent", parent);
fields.put("left", left);
fields.put("right", right);
out.writeFields();
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField fields = in.readFields();
z = fields.get("z", false);
b = fields.get("b", (byte) 0);
c = fields.get("c", (char) 0);
s = fields.get("s", (short) 0);
i = fields.get("i", (int) 0);
f = fields.get("f", (float) 0.0);
j = fields.get("j", (long) 0);
d = fields.get("d", (double) 0.0);
str = (String) fields.get("str", null);
parent = fields.get("parent", null);
left = fields.get("left", null);
right = fields.get("right", null);
}
}
/**
* Write and read a tree of objects from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <tree depth> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[] trees = genTrees(depth, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, trees, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, trees, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object trees.
*/
Node[] genTrees(int depth, int ntrees) {
Node[] trees = new Node[ntrees];
for (int i = 0; i < ntrees; i++) {
trees[i] = new Node(null, depth);
}
return trees;
}
/**
* Run benchmark for given number of batches, with each batch containing
* the given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of int array reads/writes.
*/
public class IntArrays implements Benchmark {
/**
* Write and read int arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
int[][] arrays = new int[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of int reads/writes.
*/
public class Ints implements Benchmark {
/**
* Write and read int values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeInt(0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readInt();
}
}
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of long array reads/writes.
*/
public class LongArrays implements Benchmark {
/**
* Write and read long arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
long[][] arrays = new long[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, long[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of long reads/writes.
*/
public class Longs implements Benchmark {
/**
* Write and read long values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeLong(0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readLong();
}
}
}
}

View file

@ -0,0 +1,301 @@
/*
* Copyright (c) 1999, 2016, 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
* @summary The Serialization benchmark test. This java class is used to run the
* test under JTREG.
* @library ../../
* @modules java.desktop
* @build bench.BenchInfo bench.HtmlReporter bench.Util bench.Benchmark
* @build bench.Reporter bench.XmlReporter bench.ConfigFormatException
* @build bench.Harness bench.TextReporter
* @build bench.serial.BooleanArrays bench.serial.Booleans
* @build bench.serial.ByteArrays bench.serial.Bytes bench.serial.CharArrays
* @build bench.serial.Chars bench.serial.ClassDesc bench.serial.Cons
* @build bench.serial.CustomDefaultObjTrees bench.serial.CustomObjTrees
* @build bench.serial.DoubleArrays bench.serial.Doubles
* @build bench.serial.ExternObjTrees bench.serial.FloatArrays
* @build bench.serial.Floats bench.serial.GetPutFieldTrees
* @build bench.serial.IntArrays bench.serial.Ints bench.serial.LongArrays
* @build bench.serial.Longs bench.serial.Main bench.serial.ObjArrays
* @build bench.serial.ObjTrees bench.serial.ProxyArrays
* @build bench.serial.ProxyClassDesc bench.serial.RepeatObjs
* @build bench.serial.ReplaceTrees bench.serial.ShortArrays
* @build bench.serial.Shorts bench.serial.SmallObjTrees
* @build bench.serial.StreamBuffer bench.serial.Strings
* @run main/othervm/timeout=1800 -Xss2m bench.serial.Main -c jtreg-config
* @author Mike Warres, Nigel Daley
*/
// The -Xss2m supplies additional stack space, as bench.serial.ClassDesc
// consumes a considerable amount of stack.
package bench.serial;
import bench.ConfigFormatException;
import bench.Harness;
import bench.HtmlReporter;
import bench.Reporter;
import bench.TextReporter;
import bench.XmlReporter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Timer;
import java.util.TimerTask;
/**
* Object serialization benchmark mainline.
*/
public class Main {
static final String CONFFILE = "config";
static final String VERSION = "1.3";
static final String TEST_SRC_PATH = System.getProperty("test.src") + File.separator;
static final int TEXT = 0;
static final int HTML = 1;
static final int XML = 2;
static boolean verbose;
static boolean list;
static boolean exitOnTimer;
static int testDurationSeconds;
static volatile boolean exitRequested;
static Timer timer;
static int format = TEXT;
static InputStream confstr;
static OutputStream repstr;
static Harness harness;
static Reporter reporter;
/**
* Print help message.
*/
static void usage() {
PrintStream p = System.err;
p.println("\nUsage: java -jar serialbench.jar [-options]");
p.println("\nwhere options are:");
p.println(" -h print this message");
p.println(" -v verbose mode");
p.println(" -l list configuration file");
p.println(" -t <num hours> repeat benchmarks for specified number of hours");
p.println(" -o <file> specify output file");
p.println(" -c <file> specify (non-default) configuration file");
p.println(" -html format output as html (default is text)");
p.println(" -xml format output as xml");
}
/**
* Throw RuntimeException that wrap message.
*
* @param mesg a message will be wrapped in the RuntimeException.
*/
static void die(String mesg) {
throw new RuntimeException(mesg);
}
/**
* Mainline parses command line, then hands off to benchmark harness.
*
* @param args
*/
public static void main(String[] args) {
parseArgs(args);
setupStreams();
if (list) {
listConfig();
} else {
setupHarness();
setupReporter();
if (exitOnTimer) {
setupTimer(testDurationSeconds);
do {
runBenchmarks();
} while (!exitRequested);
} else {
runBenchmarks();
}
}
}
/**
* Parse command-line arguments.
*/
static void parseArgs(String[] args) {
for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "-h":
usage();
System.exit(0);
break;
case "-v":
verbose = true;
break;
case "-l":
list = true;
break;
case "-t":
if (++i >= args.length)
die("Error: no timeout value specified");
try {
exitOnTimer = true;
testDurationSeconds = Integer.parseInt(args[i]) * 3600;
} catch (NumberFormatException e) {
die("Error: unable to determine timeout value");
}
break;
case "-o":
if (++i >= args.length)
die("Error: no output file specified");
try {
repstr = new FileOutputStream(args[i]);
} catch (FileNotFoundException e) {
die("Error: unable to open \"" + args[i] + "\"");
}
break;
case "-c":
if (++i >= args.length)
die("Error: no config file specified");
String confFileName = TEST_SRC_PATH + args[i];
try {
confstr = new FileInputStream(confFileName);
} catch (FileNotFoundException e) {
die("Error: unable to open \"" + confFileName + "\"");
}
break;
case "-html":
if (format != TEXT)
die("Error: conflicting formats");
format = HTML;
break;
case "-xml":
if (format != TEXT)
die("Error: conflicting formats");
format = XML;
break;
default:
usage();
die("Illegal option: \"" + args[i] + "\"");
}
}
}
/**
* Set up configuration file and report streams, if not set already.
*/
static void setupStreams() {
if (repstr == null)
repstr = System.out;
if (confstr == null)
confstr = Main.class.getResourceAsStream(TEST_SRC_PATH + CONFFILE);
if (confstr == null)
die("Error: unable to find default config file");
}
/**
* Print contents of configuration file to selected output stream.
*/
static void listConfig() {
try {
byte[] buf = new byte[256];
int len;
while ((len = confstr.read(buf)) != -1)
repstr.write(buf, 0, len);
} catch (IOException e) {
die("Error: failed to list config file");
}
}
/**
* Set up the timer to end the test.
*
* @param delay the amount of delay, in seconds, before requesting
* the process exit
*/
static void setupTimer(int delay) {
timer = new Timer(true);
timer.schedule(
new TimerTask() {
@Override
public void run() {
exitRequested = true;
}
},
delay * 1000);
}
/**
* Set up benchmark harness.
*/
static void setupHarness() {
try {
harness = new Harness(confstr);
} catch (ConfigFormatException e) {
String errmsg = e.getMessage();
if (errmsg != null) {
die("Error parsing config file: " + errmsg);
} else {
die("Error: illegal config file syntax");
}
} catch (IOException e) {
die("Error: failed to read config file");
}
}
/**
* Setup benchmark reporter.
*/
static void setupReporter() {
String title = "Object Serialization Benchmark, v" + VERSION;
switch (format) {
case TEXT:
reporter = new TextReporter(repstr, title);
break;
case HTML:
reporter = new HtmlReporter(repstr, title);
break;
case XML:
reporter = new XmlReporter(repstr, title);
break;
default:
die("Error: unrecognized format type");
}
}
/**
* Run benchmarks.
*/
static void runBenchmarks() {
harness.runBenchmarks(reporter, verbose);
}
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of object array reads/writes.
*/
public class ObjArrays implements Benchmark {
static class Node implements Serializable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
}
/**
* Write and read object arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[][] arrays = genArrays(size, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object arrays.
*/
Node[][] genArrays(int size, int narrays) {
Node[][] arrays = new Node[narrays][size];
for (int i = 0; i < narrays; i++) {
for (int j = 0; j < size; j++) {
arrays[i][j] = new Node(null, 0);
}
}
return arrays;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,118 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of writes and reads of an object tree.
*/
public class ObjTrees implements Benchmark {
static class Node implements Serializable {
boolean z;
byte b;
char c;
short s;
int i;
float f;
long j;
double d;
String str = "bodega";
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
}
/**
* Write and read a tree of objects from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <tree depth> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[] trees = genTrees(depth, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, trees, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, trees, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object trees.
*/
Node[] genTrees(int depth, int ntrees) {
Node[] trees = new Node[ntrees];
for (int i = 0; i < ntrees; i++) {
trees[i] = new Node(null, depth);
}
return trees;
}
/**
* Run benchmark for given number of batches, with each batch containing
* the given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,121 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* Benchmark for testing speed of proxy array reads/writes.
*/
public class ProxyArrays implements Benchmark {
static class DummyHandler implements InvocationHandler, Serializable {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
return null;
}
}
static interface DummyInterface {
public void foo();
}
/**
* Write and read proxy arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Proxy[][] arrays = genArrays(size, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate proxy arrays.
*/
Proxy[][] genArrays(int size, int narrays) throws Exception {
Class proxyClass =
Proxy.getProxyClass(DummyInterface.class.getClassLoader(),
new Class[] { DummyInterface.class });
Constructor proxyCons =
proxyClass.getConstructor(new Class[] { InvocationHandler.class });
Object[] consArgs = new Object[] { new DummyHandler() };
Proxy[][] arrays = new Proxy[narrays][size];
for (int i = 0; i < narrays; i++) {
for (int j = 0; j < size; j++) {
arrays[i][j] = (Proxy) proxyCons.newInstance(consArgs);
}
}
return arrays;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Proxy[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,127 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
/**
* Benchmark for testing speed of proxy class descriptor reads/writes.
*/
public class ProxyClassDesc implements Benchmark {
static interface A1 {};
static interface A2 {};
static interface A3 {};
static interface A4 {};
static interface A5 {};
static interface B1 {};
static interface B2 {};
static interface B3 {};
static interface B4 {};
static interface B5 {};
static interface C1 {};
static interface C2 {};
static interface C3 {};
static interface C4 {};
static interface C5 {};
/**
* Write and read proxy class descriptors to/from a stream.
* Arguments: <# cycles>
*/
public long run(String[] args) throws Exception {
int ncycles = Integer.parseInt(args[0]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
ObjectStreamClass[] descs = genDescs();
doReps(oout, oin, sbuf, descs, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, descs, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Generate proxy class descriptors.
*/
ObjectStreamClass[] genDescs() {
ClassLoader ldr = ProxyClassDesc.class.getClassLoader();
Class[] ifaces = new Class[3];
Class[] a =
new Class[] { A1.class, A2.class, A3.class, A4.class, A5.class };
Class[] b =
new Class[] { B1.class, B2.class, B3.class, B4.class, B5.class };
Class[] c =
new Class[] { C1.class, C2.class, C3.class, C4.class, C5.class };
ObjectStreamClass[] descs =
new ObjectStreamClass[a.length * b.length * c.length];
int n = 0;
for (int i = 0; i < a.length; i++) {
ifaces[0] = a[i];
for (int j = 0; j < b.length; j++) {
ifaces[1] = b[j];
for (int k = 0; k < c.length; k++) {
ifaces[2] = c[k];
Class proxyClass = Proxy.getProxyClass(ldr, ifaces);
descs[n++] = ObjectStreamClass.lookup(proxyClass);
}
}
}
return descs;
}
/**
* Run benchmark for given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, ObjectStreamClass[] descs, int ncycles)
throws Exception
{
int ndescs = descs.length;
for (int i = 0; i < ncycles; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ndescs; j++) {
oout.writeObject(descs[j]);
}
oout.flush();
for (int j = 0; j < ndescs; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of reads/writes of repeated objects.
*/
public class RepeatObjs implements Benchmark {
static class Node implements Serializable {
}
/**
* Write and read repeated objects to/from a stream. The benchmark is run
* for a given number of batches. Within each batch, a set of objects
* is written to and read from the stream. The set of objects remains the
* same between batches (and the serialization streams are not reset) in
* order to test the speed of object -> wire handle lookup, and vice versa.
* Arguments: <# objects> <# cycles>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
Node[] objs = genObjs(size);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, objs, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, objs, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate objects.
*/
Node[] genObjs(int nobjs) {
Node[] objs = new Node[nobjs];
for (int i = 0; i < nobjs; i++)
objs[i] = new Node();
return objs;
}
/**
* Run benchmark for given number of batches.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] objs, int nbatches)
throws Exception
{
int nobjs = objs.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < nobjs; j++) {
oout.writeObject(objs[j]);
}
oout.flush();
for (int j = 0; j < nobjs; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,134 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of writes and reads of a tree of replaceable
* objects.
*/
public class ReplaceTrees implements Benchmark {
static class Node implements Serializable {
Object parent, left, right;
Node(Object parent, Object left, Object right) {
this.parent = parent;
this.left = left;
this.right = right;
}
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
Object writeReplace() {
return new RepNode(parent, left, right);
}
}
static class RepNode implements Serializable {
Object parent, left, right;
RepNode(Object parent, Object left, Object right) {
this.parent = parent;
this.left = left;
this.right = right;
}
Object readResolve() {
return new Node(parent, left, right);
}
}
/**
* Write and read a tree of replaceable objects from a stream. The
* benchmark is run in batches: each "batch" consists of a fixed number of
* read/write cycles, and the stream is flushed (and underlying stream
* buffer cleared) in between each batch.
* Arguments: <tree depth> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[] trees = genTrees(depth, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, trees, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, trees, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object trees.
*/
Node[] genTrees(int depth, int ntrees) {
Node[] trees = new Node[ntrees];
for (int i = 0; i < ntrees; i++) {
trees[i] = new Node(null, depth);
}
return trees;
}
/**
* Run benchmark for given number of batches, with each batch containing
* the given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of short array reads/writes.
*/
public class ShortArrays implements Benchmark {
/**
* Write and read short arrays to/from a stream. The benchmark is run in
* batches, with each batch consisting of a fixed number of read/write
* cycles. The ObjectOutputStream is reset after each batch of cycles has
* completed.
* Arguments: <array size> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
short[][] arrays = new short[ncycles][size];
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, arrays, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, arrays, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, short[][] arrays, int nbatches)
throws Exception
{
int ncycles = arrays.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(arrays[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Benchmark for testing speed of short reads/writes.
*/
public class Shorts implements Benchmark {
/**
* Write and read short values to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int nbatches = Integer.parseInt(args[0]);
int ncycles = Integer.parseInt(args[1]);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeShort(0);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readShort();
}
}
}
}

View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* Benchmark for testing speed of writes and reads of a tree of small objects.
*/
public class SmallObjTrees implements Benchmark {
static class Node implements Serializable {
Object parent, left, right;
Node(Object parent, int depth) {
this.parent = parent;
if (depth > 0) {
left = new Node(this, depth - 1);
right = new Node(this, depth - 1);
}
}
}
/**
* Write and read a tree of small objects from a stream. The benchmark is
* run in batches: each "batch" consists of a fixed number of read/write
* cycles, and the stream is flushed (and underlying stream buffer cleared)
* in between each batch.
* Arguments: <tree depth> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int depth = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
Node[] trees = genTrees(depth, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, trees, 1); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, trees, nbatches);
return System.currentTimeMillis() - start;
}
/**
* Generate object trees.
*/
Node[] genTrees(int depth, int ntrees) {
Node[] trees = new Node[ntrees];
for (int i = 0; i < ntrees; i++) {
trees[i] = new Node(null, depth);
}
return trees;
}
/**
* Run benchmark for given number of batches, with each batch containing the
* given number of cycles.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, Node[] trees, int nbatches)
throws Exception
{
int ncycles = trees.length;
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(trees[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,168 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
/**
* The StreamBuffer class provides a space that can be written to with an
* OutputStream and read from with an InputStream. It is similar to
* PipedInput/OutputStream except that it is unsynchronized and more
* lightweight. StreamBuffers are used inside of the serialization benchmarks
* in order to minimize the overhead incurred by reading and writing to/from the
* underlying stream (using ByteArrayInput/OutputStreams results in allocation
* of a new byte array with each cycle, while using PipedInput/OutputStreams
* involves threading and synchronization).
* <p>
* Writes/reads to and from a StreamBuffer must occur in distinct phases; reads
* from a StreamBuffer effectively close the StreamBuffer output stream. These
* semantics are necessary to avoid using wait/notify in
* StreamBufferInputStream.read().
*/
public class StreamBuffer {
/**
* Output stream for writing to stream buffer.
*/
private class StreamBufferOutputStream extends OutputStream {
private int pos;
public void write(int b) throws IOException {
if (mode != WRITE_MODE)
throw new IOException();
while (pos >= buf.length)
grow();
buf[pos++] = (byte) b;
}
public void write(byte[] b, int off, int len) throws IOException {
if (mode != WRITE_MODE)
throw new IOException();
while (pos + len > buf.length)
grow();
System.arraycopy(b, off, buf, pos, len);
pos += len;
}
public void close() throws IOException {
if (mode != WRITE_MODE)
throw new IOException();
mode = READ_MODE;
}
}
/**
* Input stream for reading from stream buffer.
*/
private class StreamBufferInputStream extends InputStream {
private int pos;
public int read() throws IOException {
if (mode == CLOSED_MODE)
throw new IOException();
mode = READ_MODE;
return (pos < out.pos) ? (buf[pos++] & 0xFF) : -1;
}
public int read(byte[] b, int off, int len) throws IOException {
if (mode == CLOSED_MODE)
throw new IOException();
mode = READ_MODE;
int avail = out.pos - pos;
int rlen = (avail < len) ? avail : len;
System.arraycopy(buf, pos, b, off, rlen);
pos += rlen;
return rlen;
}
public long skip(long len) throws IOException {
if (mode == CLOSED_MODE)
throw new IOException();
mode = READ_MODE;
int avail = out.pos - pos;
long slen = (avail < len) ? avail : len;
pos += slen;
return slen;
}
public int available() throws IOException {
if (mode == CLOSED_MODE)
throw new IOException();
mode = READ_MODE;
return out.pos - pos;
}
public void close() throws IOException {
if (mode == CLOSED_MODE)
throw new IOException();
mode = CLOSED_MODE;
}
}
private static final int START_BUFSIZE = 256;
private static final int GROW_FACTOR = 2;
private static final int CLOSED_MODE = 0;
private static final int WRITE_MODE = 1;
private static final int READ_MODE = 2;
private byte[] buf;
private StreamBufferOutputStream out = new StreamBufferOutputStream();
private StreamBufferInputStream in = new StreamBufferInputStream();
private int mode = WRITE_MODE;
public StreamBuffer() {
this(START_BUFSIZE);
}
public StreamBuffer(int size) {
buf = new byte[size];
}
public OutputStream getOutputStream() {
return out;
}
public InputStream getInputStream() {
return in;
}
public void reset() {
in.pos = out.pos = 0;
mode = WRITE_MODE;
}
private void grow() {
byte[] newbuf = new byte[buf.length * GROW_FACTOR];
System.arraycopy(buf, 0, newbuf, 0, buf.length);
buf = newbuf;
}
}

View file

@ -0,0 +1,101 @@
/*
* Copyright (c) 1999, 2008, 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.
*/
/*
*
*/
package bench.serial;
import bench.Benchmark;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Random;
/**
* Benchmark for testing speed of string reads/writes.
*/
public class Strings implements Benchmark {
/**
* Write and read strings to/from a stream. The benchmark is run in
* batches: each "batch" consists of a fixed number of read/write cycles,
* and the stream is flushed (and underlying stream buffer cleared) in
* between each batch.
* Arguments: <string length> <# batches> <# cycles per batch>
*/
public long run(String[] args) throws Exception {
int slen = Integer.parseInt(args[0]);
int nbatches = Integer.parseInt(args[1]);
int ncycles = Integer.parseInt(args[2]);
String[] strs = genStrings(slen, ncycles);
StreamBuffer sbuf = new StreamBuffer();
ObjectOutputStream oout =
new ObjectOutputStream(sbuf.getOutputStream());
ObjectInputStream oin =
new ObjectInputStream(sbuf.getInputStream());
doReps(oout, oin, sbuf, strs, 1, ncycles); // warmup
long start = System.currentTimeMillis();
doReps(oout, oin, sbuf, strs, nbatches, ncycles);
return System.currentTimeMillis() - start;
}
/**
* Generate nstrings random strings, each of length len.
*/
String[] genStrings(int len, int nstrings) {
String[] strs = new String[nstrings];
char[] ca = new char[len];
Random rand = new Random(System.currentTimeMillis());
for (int i = 0; i < nstrings; i++) {
for (int j = 0; j < len; j++) {
ca[j] = (char) rand.nextInt();
}
strs[i] = new String(ca);
}
return strs;
}
/**
* Run benchmark for given number of batches, with given number of cycles
* for each batch.
*/
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
StreamBuffer sbuf, String[] strs, int nbatches, int ncycles)
throws Exception
{
for (int i = 0; i < nbatches; i++) {
sbuf.reset();
oout.reset();
for (int j = 0; j < ncycles; j++) {
oout.writeObject(strs[j]);
}
oout.flush();
for (int j = 0; j < ncycles; j++) {
oin.readObject();
}
}
}
}

View file

@ -0,0 +1,140 @@
#
# Configuration file for serialization benchmarks
#
# Time object tree reads/writes with custom writeObject/readObject methods
# Arguments: <tree depth> <# batches> <# cycles per batch>
0.0 "Warmup: read/writeObject trees" bench.serial.CustomObjTrees 6 200 5000
# Time object tree reads/writes using defaultWriteObject/defaultReadObject
# Arguments: <tree depth> <# batches> <# cycles per batch>
0.0 "Warmup: defaultRead/WriteObject trees" bench.serial.CustomDefaultObjTrees 6 200 5000
# Time object stream construction
# Arguments: <# repetitions>
1.0 "Object stream construction" bench.serial.Cons 200000
# Time boolean reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Booleans" bench.serial.Booleans 500 10000
# Time byte reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Bytes" bench.serial.Bytes 500 10000
# Time char reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Chars" bench.serial.Chars 500 10000
# Time short reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Shorts" bench.serial.Shorts 500 10000
# Time int reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Ints" bench.serial.Ints 500 10000
# Time long reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Longs" bench.serial.Longs 500 10000
# Time float reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Floats" bench.serial.Floats 500 10000
# Time double reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Doubles" bench.serial.Doubles 500 10000
# Time boolean array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Boolean arrays" bench.serial.BooleanArrays 500 100 100
# Time byte array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Byte arrays" bench.serial.ByteArrays 500 100 100
# Time char array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Char arrays" bench.serial.CharArrays 500 100 100
# Time short array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Short arrays" bench.serial.ShortArrays 500 100 100
# Time int array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Int arrays" bench.serial.IntArrays 500 100 100
# Time long array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Long arrays" bench.serial.LongArrays 500 100 100
# Time float array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Float arrays" bench.serial.FloatArrays 500 100 100
# Time double array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Double arrays" bench.serial.DoubleArrays 500 100 100
# Time short string reads/writes
# Arguments: <string length> <# batches> <# cycles per batch>
1.0 "Short strings" bench.serial.Strings 10 1000 1000
# Time long string reads/writes
# Arguments: <string length> <# batches> <# cycles per batch>
1.0 "Long strings" bench.serial.Strings 300 100 1000
# Time object array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Object arrays" bench.serial.ObjArrays 100 100 100
# Time object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "Object trees" bench.serial.ObjTrees 6 100 1000
# Time externalizable-object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "Externalizable-object trees" bench.serial.ExternObjTrees 6 100 1000
# Time object tree reads/writes with custom writeObject/readObject methods
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "read/writeObject trees" bench.serial.CustomObjTrees 6 100 1000
# Time object tree reads/writes using defaultWriteObject/defaultReadObject
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "defaultRead/WriteObject trees" bench.serial.CustomDefaultObjTrees 6 100 1000
# Time GetField/PutField API
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "GetField/PutField trees" bench.serial.GetPutFieldTrees 6 100 1000
# Time replaceable-object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "writeReplace/readResolve trees" bench.serial.ReplaceTrees 6 10000 1
# Time small-object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "Small-object trees" bench.serial.SmallObjTrees 6 100 100
# Time repeated object reads/writes
# Arguments: <# objects> <# batches>
1.0 "Repeated objects" bench.serial.RepeatObjs 1000 10000
# Time class descriptor reads/writes
# Arguments: <# cycles>
1.0 "Class descriptors" bench.serial.ClassDesc 20000
#
# NOTE: the following two benchmarks should be commented out unless you are
# running Java 2 version 1.3 or higher.
#
# Time proxy class descriptor reads/writes
# Arguments: <# cycles>
1.0 "Proxy class descriptors" bench.serial.ProxyClassDesc 20000
# Time proxy array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Proxy arrays" bench.serial.ProxyArrays 100 100 100

View file

@ -0,0 +1,137 @@
#
# Configuration file for serialization benchmarks
#
# Warmup (Time class descriptor reads/writes)
# Arguments: <tree depth> <# batches> <# cycles per batch>
0.0 "Warmup" bench.serial.SmallObjTrees 6 100 100
# Time object stream construction
# Arguments: <# repetitions>
1.0 "Object stream construction" bench.serial.Cons 100000
# Time boolean reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Booleans" bench.serial.Booleans 250 5000
# Time byte reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Bytes" bench.serial.Bytes 250 5000
# Time char reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Chars" bench.serial.Chars 250 5000
# Time short reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Shorts" bench.serial.Shorts 250 5000
# Time int reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Ints" bench.serial.Ints 250 5000
# Time long reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Longs" bench.serial.Longs 250 5000
# Time float reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Floats" bench.serial.Floats 250 5000
# Time double reads/writes
# Arguments: <# batches> <# cycles per batch>
1.0 "Doubles" bench.serial.Doubles 250 5000
# Time boolean array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Boolean arrays" bench.serial.BooleanArrays 250 50 50
# Time byte array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Byte arrays" bench.serial.ByteArrays 250 50 50
# Time char array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Char arrays" bench.serial.CharArrays 250 50 50
# Time short array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Short arrays" bench.serial.ShortArrays 250 50 50
# Time int array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Int arrays" bench.serial.IntArrays 250 50 50
# Time long array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Long arrays" bench.serial.LongArrays 250 50 50
# Time float array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Float arrays" bench.serial.FloatArrays 250 50 50
# Time double array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Double arrays" bench.serial.DoubleArrays 250 50 50
# Time short string reads/writes
# Arguments: <string length> <# batches> <# cycles per batch>
1.0 "Short strings" bench.serial.Strings 5 500 500
# Time long string reads/writes
# Arguments: <string length> <# batches> <# cycles per batch>
1.0 "Long strings" bench.serial.Strings 150 50 50
# Time object array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Object arrays" bench.serial.ObjArrays 50 50 50
# Time object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "Object trees" bench.serial.ObjTrees 3 50 500
# Time externalizable-object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "Externalizable-object trees" bench.serial.ExternObjTrees 3 50 500
# Time object tree reads/writes with custom writeObject/readObject methods
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "read/writeObject trees" bench.serial.CustomObjTrees 3 50 500
# Time object tree reads/writes using defaultWriteObject/defaultReadObject
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "defaultRead/WriteObject trees" bench.serial.CustomDefaultObjTrees 3 50 500
# Time GetField/PutField API
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "GetField/PutField trees" bench.serial.GetPutFieldTrees 3 50 500
# Time replaceable-object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "writeReplace/readResolve trees" bench.serial.ReplaceTrees 3 5000 1
# Time small-object tree reads/writes
# Arguments: <tree depth> <# batches> <# cycles per batch>
1.0 "Small-object trees" bench.serial.SmallObjTrees 3 50 50
# Time repeated object reads/writes
# Arguments: <# objects> <# batches>
1.0 "Repeated objects" bench.serial.RepeatObjs 500 5000
# Time class descriptor reads/writes
# Arguments: <# cycles>
1.0 "Class descriptors" bench.serial.ClassDesc 10000
#
# NOTE: the following two benchmarks should be commented out unless you are
# running Java 2 version 1.3 or higher.
#
# Time proxy class descriptor reads/writes
# Arguments: <# cycles>
1.0 "Proxy class descriptors" bench.serial.ProxyClassDesc 10000
# Time proxy array reads/writes
# Arguments: <array size> <# batches> <# cycles per batch>
1.0 "Proxy arrays" bench.serial.ProxyArrays 50 50 50

View file

@ -0,0 +1 @@
Main-Class: bench.serial.Main

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2003, 2008, 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.rmi.Remote;
import java.rmi.RemoteException;
/**
* A remote factory for Orange instances. This interface also
* includes a method to test object array serialization.
*/
public interface Apple extends Remote {
void notify(AppleEvent[] e) throws RemoteException;
Orange newOrange(String name) throws RemoteException;
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2003, 2008, 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.io.Serializable;
import java.util.Date;
/**
* The AppleEvent class is simply an object to be passed to a
* remote object exported by an applet. The intent is to verify
* proper object serialization of arrays.
*/
public class AppleEvent implements Serializable {
public static final int BUY = 0;
public static final int EAT = 1;
public static final int THROW = 2;
private final int what;
private final Date when;
public AppleEvent(int what) {
this.what = what;
this.when = new Date();
}
public String toString() {
String desc = "[";
switch (what) {
case BUY:
desc += "BUY";
break;
case EAT:
desc += "EAT";
break;
case THROW:
desc += "THROW";
break;
}
desc += " @ " + when + "]";
return desc;
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright (c) 2003, 2008, 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.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* The AppleImpl class implements the behavior of the remote "apple"
* objects exported by the application.
*/
public class AppleImpl extends UnicastRemoteObject implements Apple {
private static final Logger logger = Logger.getLogger("reliability.apple");
private final String name;
public AppleImpl(String name) throws RemoteException {
this.name = name;
}
/**
* Receive an array of AppleEvent objects.
*/
public void notify(AppleEvent[] events) {
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": " + toString() + ".notify: BEGIN");
for (int i = 0; i < events.length; i++) {
logger.log(Level.FINEST,
threadName + ": " + toString() + ".notify(): events["
+ i + "] = " + events[i].toString());
}
logger.log(Level.FINEST,
threadName + ": " + toString() + ".notify(): END");
}
/**
* Return a newly created and exported orange implementation.
*/
public Orange newOrange(String name) throws RemoteException {
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": " + toString() + ".newOrange(" + name + "): BEGIN");
Orange orange = new OrangeImpl(name);
logger.log(Level.FINEST,
threadName + ": " + toString() + ".newOrange(" + name + "): END");
return orange;
}
public String toString() {
return name;
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2003, 2008, 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.rmi.Remote;
import java.rmi.RemoteException;
/**
* AppleUser is a remote interface that allows the application server
* (a generator of Apple objects) to pass Apple objects and to
* communicate various conditions to the implementation of this interface.
*/
public interface AppleUser extends Remote {
void startTest() throws RemoteException;
void reportException(Exception status) throws RemoteException;
void useApple(Apple apple) throws RemoteException;
}

View file

@ -0,0 +1,387 @@
/*
* Copyright (c) 2003, 2024, 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
*
* @summary The juicer is the classic RMI stress test. The juicer makes
* a large number of concurrent, long running, remote method invocations
* between many threads which have exported remote objects. These
* threads use remote objects that carry on deep "two party"
* recursion. The juicer relies on Distributed Garbage Collection to
* unexport these remote objects when no more references are held to them.
* The two parties in the recursion are OrangeImpl and
* OrangeEchoImpl. OrangeImpl checks the base case of the recursion
* so that the program will exit.
*
* When the AppleUserImpl.main() method is invoked, the class binds an
* instance of itself in a registry. A second server process,
* an ApplicationServer, is started which looks up the recently
* bound AppleUser object. This server is either started up in
* the same VM or can optionally be started in a separate VM on the
* same host or on a different host. When this test is run on the
* RMI profile, ApplicationServer must be started by AppleUserImpl
* and the complete juicer runs in a single process.
*
* The second server process instructs the AppleUserImpl to "use" some apples.
* AppleUserImpl creates a new thread for each apple. These threads
* initiate the two party recursion.
*
* Each recursive call nests to a depth determined by this
* expression: (2 + Math.abs(random.nextInt() % (maxLevel + 1)),
* where maxLevel is a command line parameter. Thus each recursive
* call nests a random number of levels between 2 and maxLevel.
*
* The test ends when an exception is encountered or the stop time
* has been reached.
*
* @library ../../testlibrary
* @modules java.rmi/sun.rmi.registry
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary
* Apple AppleEvent AppleImpl
* Orange OrangeEcho OrangeEchoImpl OrangeImpl
* ApplicationServer
*
* @run main/othervm AppleUserImpl -seconds 30
*
* @author Peter Jones, Nigel Daley
*/
import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* The AppleUserImpl class implements the behavior of the remote
* "apple user" objects exported by the server. The application server
* passes each of its remote "apple" objects to an apple user, and an
* AppleUserThread is created for each apple.
*/
public class AppleUserImpl extends UnicastRemoteObject implements AppleUser {
private static int registryPort = -1;
private static final Logger logger =
Logger.getLogger("reliability.appleuser");
private static int threadNum = 0;
private static long testDuration = 0;
private static int maxLevel = 7;
private static Exception status = null;
private static boolean finished = false;
private static boolean startTestNotified = false;
private static final Random random = new Random();
private static final Object lock = new Object();
public AppleUserImpl() throws RemoteException {
}
/**
* Allows the other server process to indicate that it is ready
* to start "juicing".
*/
public synchronized void startTest() throws RemoteException {
startTestNotified = true;
this.notifyAll();
}
/**
* Allows the other server process to report an exception to this
* process and thereby terminate the test.
*/
public void reportException(Exception status) throws RemoteException {
synchronized (lock) {
this.status = status;
lock.notifyAll();
}
}
/**
* "Use" supplied apple object. Create an AppleUserThread to
* stress it out.
*/
public synchronized void useApple(Apple apple) throws RemoteException {
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": AppleUserImpl.useApple(): BEGIN");
AppleUserThread t =
new AppleUserThread("AppleUserThread-" + (++threadNum), apple);
t.start();
logger.log(Level.FINEST,
threadName + ": AppleUserImpl.useApple(): END");
}
/**
* The AppleUserThread class repeatedly invokes calls on its associated
* Apple object to stress the RMI system.
*/
class AppleUserThread extends Thread {
final Apple apple;
public AppleUserThread(String name, Apple apple) {
super(name);
this.apple = apple;
}
public void run() {
int orangeNum = 0;
long stopTime = System.currentTimeMillis() + testDuration;
Logger logger = Logger.getLogger("reliability.appleuserthread");
try {
do { // loop until stopTime is reached
/*
* Notify apple with some apple events. This tests
* serialization of arrays.
*/
int numEvents = Math.abs(random.nextInt() % 5);
AppleEvent[] events = new AppleEvent[numEvents];
for (int i = 0; i < events.length; i++) {
events[i] = new AppleEvent(orangeNum % 3);
}
apple.notify(events);
/*
* Request a new orange object be created in
* the application server.
*/
Orange orange = apple.newOrange(
"Orange(" + getName() + ")-" + (++orangeNum));
/*
* Create a large message of random ints to pass to orange.
*/
int msgLength = 1000 + Math.abs(random.nextInt() % 3000);
int[] message = new int[msgLength];
for (int i = 0; i < message.length; i++) {
message[i] = random.nextInt();
}
/*
* Invoke recursive call on the orange. Base case
* of recursion inverts messgage.
*/
OrangeEchoImpl echo = new OrangeEchoImpl(
"OrangeEcho(" + getName() + ")-" + orangeNum);
int[] response = orange.recurse(echo, message,
2 + Math.abs(random.nextInt() % (maxLevel + 1)));
/*
* Verify message was properly inverted and not corrupted
* through all the recursive method invocations.
*/
if (response.length != message.length) {
throw new RuntimeException(
"ERROR: CORRUPTED RESPONSE: " +
"wrong length of returned array " + "(should be " +
message.length + ", is " + response.length + ")");
}
for (int i = 0; i < message.length; i++) {
if (~message[i] != response[i]) {
throw new RuntimeException(
"ERROR: CORRUPTED RESPONSE: " +
"at element " + i + "/" + message.length +
" of returned array (should be " +
Integer.toHexString(~message[i]) + ", is " +
Integer.toHexString(response[i]) + ")");
}
}
try {
Thread.sleep(Math.abs(random.nextInt() % 10) * 1000);
} catch (InterruptedException e) {
}
} while (System.currentTimeMillis() < stopTime);
} catch (Exception e) {
status = e;
}
finished = true;
synchronized (lock) {
lock.notifyAll();
}
}
}
private static void usage() {
System.err.println("Usage: AppleUserImpl [-hours <hours> | " +
"-seconds <seconds>]");
System.err.println(" [-maxLevel <maxLevel>]");
System.err.println(" [-othervm]");
System.err.println(" [-exit]");
System.err.println(" hours The number of hours to run the juicer.");
System.err.println(" The default is 0 hours.");
System.err.println(" seconds The number of seconds to run the juicer.");
System.err.println(" The default is 0 seconds.");
System.err.println(" maxLevel The maximum number of levels to ");
System.err.println(" recurse on each call.");
System.err.println(" The default is 7 levels.");
System.err.println(" othervm If present, the VM will wait for the");
System.err.println(" ApplicationServer to start in");
System.err.println(" another process.");
System.err.println(" The default is to run everything in");
System.err.println(" a single VM.");
System.err.println(" exit If present, the VM will call");
System.err.println(" System.exit() when main() finishes.");
System.err.println(" The default is to not call");
System.err.println(" System.exit().");
System.err.println();
}
/**
* Entry point for the "juicer" server process. Create and export
* an apple user implementation in an rmiregistry running on localhost.
*/
public static void main(String[] args) {
String durationString = null;
boolean othervm = false;
boolean exit = false;
try {
// parse command line args
for (int i = 0; i < args.length ; i++ ) {
String arg = args[i];
if (arg.equals("-hours")) {
if (durationString != null) {
usage();
}
i++;
int hours = Integer.parseInt(args[i]);
durationString = hours + " hours";
testDuration = hours * 60 * 60 * 1000;
} else if (arg.equals("-seconds")) {
if (durationString != null) {
usage();
}
i++;
long seconds = Long.parseLong(args[i]);
durationString = seconds + " seconds";
testDuration = seconds * 1000;
} else if (arg.equals("-maxLevel")) {
i++;
maxLevel = Integer.parseInt(args[i]);
} else if (arg.equals("-othervm")) {
othervm = true;
} else if (arg.equals("-exit")) {
exit = true;
} else {
usage();
}
}
if (durationString == null) {
durationString = testDuration + " milliseconds";
}
} catch (Throwable t) {
usage();
throw new RuntimeException("TEST FAILED: Bad argument");
}
AppleUserImpl user = null;
long startTime = 0;
Thread server = null;
int exitValue = 0;
try {
user = new AppleUserImpl();
synchronized (user) {
// create new registry and bind new AppleUserImpl in registry
Registry registry = TestLibrary.createRegistryOnEphemeralPort();
registryPort = TestLibrary.getRegistryPort(registry);
LocateRegistry.getRegistry(registryPort).rebind("AppleUser",
user);
// start the other server if applicable
if (othervm) {
// the other server must be running in a separate process
logger.log(Level.INFO, "Application server must be " +
"started in separate process");
} else {
Class app = Class.forName("ApplicationServer");
java.lang.reflect.Constructor appConstructor =
app.getDeclaredConstructor(new Class[] {Integer.TYPE});
server = new Thread((Runnable) appConstructor.newInstance(registryPort));
logger.log(Level.INFO, "Starting application server " +
"in same process");
server.start();
}
// wait for other server to call startTest method
logger.log(Level.INFO, "Waiting for application server " +
"process to start");
while (!startTestNotified) {
user.wait();
}
}
startTime = System.currentTimeMillis();
logger.log(Level.INFO, "Test starting");
// wait for exception to be reported or first thread to complete
logger.log(Level.INFO, "Waiting " + durationString + " for " +
"test to complete or exception to be thrown");
synchronized (lock) {
while (status == null && !finished) {
lock.wait();
}
}
if (status != null) {
throw new RuntimeException("TEST FAILED: "
+ "juicer server reported an exception", status);
} else {
logger.log(Level.INFO, "TEST PASSED");
}
} catch (Exception e) {
logger.log(Level.INFO, "TEST FAILED");
exitValue = 1;
if (exit) {
e.printStackTrace();
}
throw new RuntimeException("TEST FAILED: "
+ "unexpected exception", e);
} finally {
long actualDuration = System.currentTimeMillis() - startTime;
logger.log(Level.INFO, "Test finished");
try {
UnicastRemoteObject.unexportObject(user, true);
} catch (NoSuchObjectException ignore) {
}
logger.log(Level.INFO, "Test duration was " +
(actualDuration/1000) + " seconds " +
"(" + (actualDuration/3600000) + " hours)");
System.gc(); System.gc();
if (exit) {
System.exit(exitValue);
}
}
}
}

View file

@ -0,0 +1,181 @@
/*
* Copyright (c) 2003, 2012, 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.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* The ApplicationServer class provides the other server side of the "juicer"
* stress test of RMI.
*/
public class ApplicationServer implements Runnable {
/** number of remote Apple objects to export */
private static final Logger logger = Logger.getLogger("reliability.orange");
private static final int LOOKUP_ATTEMPTS = 5;
private static final int DEFAULT_NUMAPPLES = 10;
private static final String DEFAULT_REGISTRYHOST = "localhost";
private static final int DEFAULT_REGISTRYPORT = -1;
private final int numApples;
private final String registryHost;
private final int registryPort;
private final Apple[] apples;
private AppleUser user;
ApplicationServer(int registryPort) {
this(DEFAULT_NUMAPPLES, DEFAULT_REGISTRYHOST, registryPort);
}
ApplicationServer(int numApples, String registryHost, int registryPort) {
this.numApples = numApples;
this.registryHost = registryHost;
this.registryPort = registryPort;
apples = new Apple[numApples];
}
/*
* On initialization, export remote objects and register
* them with server.
*/
@Override
public void run() {
try {
int i = 0;
/*
* Locate apple user object in registry. The lookup will occur
* every 5 seconds until it is successful or timeout 50 seconds.
* These repeated attempts allow the ApplicationServer
* to be started before the AppleUserImpl.
*/
Exception exc = null;
long stopTime = System.currentTimeMillis() + LOOKUP_ATTEMPTS * 10000;
while (System.currentTimeMillis() < stopTime) {
try {
Registry registry = LocateRegistry.getRegistry(
registryHost, registryPort);
user = (AppleUser) registry.lookup("AppleUser");
user.startTest();
break; //successfully obtained AppleUser
} catch (RemoteException | NotBoundException e) {
exc = e;
Thread.sleep(5000); //sleep 5 seconds and try again
}
}
if (user == null) {
logger.log(Level.SEVERE, "Failed to lookup AppleUser:", exc);
return;
}
/*
* Create and export apple implementations.
*/
try {
for (i = 0; i < numApples; i++) {
apples[i] = new AppleImpl("AppleImpl #" + (i + 1));
}
} catch (RemoteException e) {
logger.log(Level.SEVERE,
"Failed to create AppleImpl #" + (i + 1) + ":", e);
user.reportException(e);
return;
}
/*
* Hand apple objects to apple user.
*/
try {
for (i = 0; i < numApples; i++) {
user.useApple(apples[i]);
}
} catch (RemoteException e) {
logger.log(Level.SEVERE,
"Failed to register callbacks for " + apples[i] + ":", e);
user.reportException(e);
}
} catch (InterruptedException | RemoteException e) {
logger.log(Level.SEVERE, "Unexpected exception:", e);
}
}
private static void usage() {
System.err.println("Usage: ApplicationServer [-numApples <numApples>]");
System.err.println(" [-registryHost <host>]");
System.err.println(" -registryPort <port>");
System.err.println(" numApples The number of apples (threads) to use.");
System.err.println(" The default is 10 apples.");
System.err.println(" host The host running rmiregistry " +
"which contains AppleUser.");
System.err.println(" The default is \"localhost\".");
System.err.println(" port The port the rmiregistry is running" +
"on.");
System.err.println();
}
public static void main(String[] args) {
int num = DEFAULT_NUMAPPLES;
int port = -1;
String host = DEFAULT_REGISTRYHOST;
// parse command line args
try {
for (int i = 0; i < args.length ; i++ ) {
String arg = args[i];
switch (arg) {
case "-numApples":
i++;
num = Integer.parseInt(args[i]);
break;
case "-registryHost":
i++;
host = args[i];
break;
case "-registryPort":
i++;
port = Integer.parseInt(args[i]);
break;
default:
usage();
break;
}
}
if (port == -1) {
usage();
throw new RuntimeException("Port must be specified.");
}
} catch (Throwable t) {
usage();
throw new RuntimeException("TEST FAILED: Bad argument");
}
// start the client server
Thread server = new Thread(new ApplicationServer(num,host,port));
server.start();
// main should exit once all exported remote objects are gc'd
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2003, 2008, 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.rmi.Remote;
import java.rmi.RemoteException;
/**
* Represents one remote party of the deep 2-party recursion implemented by
* this RMI reliability test. An Orange instance recursively calls back
* to it's caller, typically an OrangeEcho instance.
* The recursion stops when it reaches a given 'level'.
*/
public interface Orange extends Remote {
int[] recurse(OrangeEcho echo, int[] message, int level)
throws RemoteException;
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2003, 2008, 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.rmi.Remote;
import java.rmi.RemoteException;
/**
* Represents one remote party of the deep 2-party recursion implemented by
* this RMI reliability test. An OrangeEcho instance recursively calls back
* to it's caller, an Orange instance.
* The recursion stops when it reaches a given 'level'.
*/
public interface OrangeEcho extends Remote {
int[] recurse(Orange orange, int[] message, int level)
throws RemoteException;
}

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2003, 2008, 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.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* The OrangeEchoImpl class implements the behavior of the remote "orange
* echo" objects exported by the server. The purpose of these objects
* is simply to recursively call back to their caller.
*/
public class OrangeEchoImpl extends UnicastRemoteObject implements OrangeEcho {
private static final Logger logger =
Logger.getLogger("reliability.orangeecho");
private final String name;
public OrangeEchoImpl(String name) throws RemoteException {
this.name = name;
}
/**
* Call back on supplied "orange" object (presumably the caller)
* with the same message data and a decremented recursion level.
*/
public int[] recurse(Orange orange, int[] message, int level)
throws RemoteException
{
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": " + toString() + ".recurse(message["
+ message.length + "], " + level + "): BEGIN");
int[] response = orange.recurse(this, message, level - 1);
logger.log(Level.FINEST,
threadName + ": " + toString() + ".recurse(message["
+ message.length + "], " + level + "): END");
return response;
}
public String toString() {
return name;
}
}

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2003, 2008, 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.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* The OrangeImpl class implements the behavior of the remote "orange"
* objects exported by the appplication.
*/
public class OrangeImpl extends UnicastRemoteObject implements Orange {
private static final Logger logger = Logger.getLogger("reliability.orange");
private final String name;
public OrangeImpl(String name) throws RemoteException {
this.name = name;
}
/**
* Return inverted message data, call through supplied OrangeEcho
* object if not at recursion level zero.
*/
public int[] recurse(OrangeEcho echo, int[] message, int level)
throws RemoteException
{
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": " + toString() + ".recurse(message["
+ message.length + "], " + level + "): BEGIN");
int[] response;
if (level > 0) {
response = echo.recurse(this, message, level);
} else {
for (int i = 0; i < message.length; i++) {
message[i] = ~message[i];
}
response = message;
}
logger.log(Level.FINEST,
threadName + ": " + toString() + ".recurse(message["
+ message.length + "], " + level + "): END");
return response;
}
public String toString() {
return name;
}
}

View file

@ -0,0 +1,136 @@
#
# Copyright (c) 2003, 2020, 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.
#
#!/bin/ksh
#
# Script to build and launch the RMI reliability suite.
# This script is used to run the reliability test for a
# certain number of hours. This script is NOT used when
# running the juicer and benchmark tests as part of the
# jtreg regression suite.
JAVA_HOME=$1
WORK_DIR=$2
RES_DIR=$3
SHELLTOUSE=$4
SUITE_DIR=$5
NHOURS=$6
shift 6
VMOPTS=$*
###You need not export these variables if your reliability run is from this shell itself######
###If you are launching another shell then you need to export these variables.#######
if [ "${WORK_DIR}" = "" ] ; then
WORK_DIR=`pwd`
fi
if [ "${RES_DIR}" = "" ] ; then
RES_DIR=`pwd`/results
fi
if [ "${SHELLTOUSE}" = "" ] ; then
SHELLTOUSE=ksh
fi
if [ "${JAVA_HOME}" = "" ] ; then
WHENCEJAVA=`whence java`
JAVABIN=`dirname ${WHENCEJAVA}`
JAVA_HOME=`dirname ${JAVABIN}`
fi
if [ "${SUITE_DIR}" = "" ] ; then
SUITE_DIR=`pwd`
fi
if [ "${VMOPTS}" = "" ] ; then
VMOPTS=-server -showversion
fi
if [ "${NHOURS}" = "" ] ; then
NHOURS=1
fi
export JAVA_HOME
export WORK_DIR
export RES_DIR
export SHELLTOUSE
export SUITE_DIR
export NHOURS
export VMOPTS
echo "######### launch_reliability script ##########"
echo "JAVA_HOME : $JAVA_HOME "
echo "WORK_DIR : $WORK_DIR "
echo "RES_DIR : $RES_DIR "
echo "SHELLTOUSE : $SHELLTOUSE "
echo "SUITE_DIR : $SUITE_DIR "
echo "NHOURS : $NHOURS "
echo "VMOPTS : $VMOPTS "
# set platform-dependent variables
if [ `uname` = "Linux" ] ; then
PATH_SEP=":"
else
PATH_SEP=";"
fi
export PATH_SEP
mainpid=$$
mkdir -p ${RES_DIR}
rm -rf ${WORK_DIR}/rmibench_scratch
rm -rf ${WORK_DIR}/serialbench_scratch
rm -rf ${WORK_DIR}/juicer_scratch
mkdir -p ${WORK_DIR}/rmibench_scratch
mkdir -p ${WORK_DIR}/serialbench_scratch
mkdir -p ${WORK_DIR}/juicer_scratch
echo ""
echo " Starting RMI bench test "
$SHELLTOUSE ${SUITE_DIR}/scripts/run_rmibench.ksh ${WORK_DIR}/rmibench_scratch $RES_DIR $JAVA_HOME $SUITE_DIR $NHOURS $VMOPTS &
pid1=$!
sleep 30
echo ""
echo " Starting Serialization bench test "
$SHELLTOUSE ${SUITE_DIR}/scripts/run_serialbench.ksh ${WORK_DIR}/serialbench_scratch $RES_DIR $JAVA_HOME $SUITE_DIR $NHOURS $VMOPTS &
pid2=$!
sleep 30
echo ""
echo " Starting RMI juicer test "
$SHELLTOUSE ${SUITE_DIR}/scripts/run_juicer.ksh ${WORK_DIR}/juicer_scratch $RES_DIR $JAVA_HOME $SUITE_DIR $NHOURS $VMOPTS &
pid3=$!
sleep 30
echo ""
echo " Waiting for jobs to complete"
wait $pid1 $pid2 $pid3
echo ""
echo " Done RMI reliability testing "
rm -rf ${WORK_DIR}/rmibench_scratch
rm -rf ${WORK_DIR}/serialbench_scratch
rm -rf ${WORK_DIR}/juicer_scratch
kill -9 $mainpid

View file

@ -0,0 +1,68 @@
#
# Copyright (c) 2005, 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.
#
#!/bin/ksh
#
# Script to create rmibench.jar and serialbench files that are delivered to
# the Performance Group (http://perfwww.ireland/).
echo "*******************************************************"
echo "CREATING rmibench.jar"
echo "*******************************************************"
rm -rf /tmp/rmibench
rm -f `pwd`/rmibench.jar
mkdir -p /tmp/rmibench
cp -r ../benchmark/bench /tmp/rmibench/
rm -rf /tmp/rmibench/bench/SCCS
rm -rf /tmp/rmibench/bench/rmi/SCCS
rm -rf /tmp/rmibench/bench/serial
rm -rf /tmp/rmibench/bench/rmi/altroot/SCCS
javac \
/tmp/rmibench/bench/rmi/altroot/*.java \
/tmp/rmibench/bench/rmi/*.java \
/tmp/rmibench/bench/*.java
jar cvfm `pwd`/rmibench.jar /tmp/rmibench/bench/rmi/manifest -C /tmp/rmibench .
echo "*******************************************************"
echo "CREATING serialbench.jar"
echo "*******************************************************"
rm -rf /tmp/serialbench
rm -f `pwd`/serialbench.jar
mkdir -p /tmp/serialbench
cp -r ../benchmark/bench /tmp/serialbench/
rm -rf /tmp/serialbench/bench/SCCS
rm -rf /tmp/serialbench/bench/serial/SCCS
rm -rf /tmp/serialbench/bench/rmi
javac \
/tmp/serialbench/bench/serial/*.java \
/tmp/serialbench/bench/*.java
jar cvfm `pwd`/serialbench.jar /tmp/serialbench/bench/serial/manifest -C /tmp/serialbench .

View file

@ -0,0 +1,79 @@
#
# Copyright (c) 2003, 2005, 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.
#
#!/bin/ksh
#
# Script to build and launch the juicer test as part of
# the RMI reliability test. This script is used to run
# the juicer test for a certain number of hours. This
# script is NOT used when running the juicer test as part
# of the jtreg regression suite.
WORK_DIR=$1
RES_DIR=$2
JAVA_HOME=$3
SUITE_DIR=$4
NHOURS=$5
shift 5
VMOPTS=$*
echo " ######### run_juicer script ##########"
echo " WORK_DIR : $WORK_DIR "
echo " RES_DIR : $RES_DIR "
echo " JAVA_HOME : $JAVA_HOME "
echo " SUITE_DIR : $SUITE_DIR "
echo " NHOURS : $NHOURS "
echo " VMOPTS : $VMOPTS "
${JAVA_HOME}/bin/javac \
-d $WORK_DIR \
${SUITE_DIR}/juicer/*.java
echo " Starting ApplicationServer "
${JAVA_HOME}/bin/java \
$VMOPTS \
-cp $WORK_DIR \
-Djava.security.policy=${SUITE_DIR}/juicer/security.policy \
ApplicationServer \
> ${RES_DIR}/log.juicer.appserver 2>&1 &
pid1=$!
echo " Starting AppleUserImpl"
${JAVA_HOME}/bin/java \
$VMOPTS \
-cp $WORK_DIR \
-Djava.security.policy=${SUITE_DIR}/juicer/security.policy \
AppleUserImpl \
-maxLevel 9 -hours ${NHOURS} -othervm -exit \
> ${RES_DIR}/log.juicer.appleuser 2>&1
RETVAL=$?
kill -9 $pid1
echo " Juicer test finished with exit value ${RETVAL}"
exit ${RETVAL}

View file

@ -0,0 +1,86 @@
#
# Copyright (c) 2003, 2005, 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.
#
#!/bin/ksh
#
# Script to build and launch the RMI bench test as part of
# the RMI reliability test. This script is used to run
# the bench test for a certain number of hours. This
# script is NOT used when running the bench test as part
# of the jtreg regression suite.
WORK_DIR=$1
RES_DIR=$2
JAVA_HOME=$3
SUITE_DIR=$4
NHOURS=$5
shift 5
VMOPTS=$*
echo " ######### run_rmibench script ##########"
echo " WORK_DIR : $WORK_DIR "
echo " RES_DIR : $RES_DIR "
echo " JAVA_HOME : $JAVA_HOME "
echo " SUITE_DIR : $SUITE_DIR "
echo " NHOURS : $NHOURS "
echo " VMOPTS : $VMOPTS "
${JAVA_HOME}/bin/javac \
-d $WORK_DIR \
${SUITE_DIR}/benchmark/bench/rmi/altroot/*.java \
${SUITE_DIR}/benchmark/bench/rmi/*.java \
${SUITE_DIR}/benchmark/bench/*.java
echo " Starting RMI benchmark server "
${JAVA_HOME}/bin/java \
$VMOPTS \
-cp $WORK_DIR \
-Djava.security.policy=${SUITE_DIR}/benchmark/bench/rmi/policy.all \
bench.rmi.Main \
-t $NHOURS \
-v \
-server 2007 \
-c ${SUITE_DIR}/benchmark/bench/rmi/config \
> ${RES_DIR}/log.rmibench.server 2>&1 &
sleep 10
echo " Starting RMI benchmark client "
${JAVA_HOME}/bin/java \
$VMOPTS \
-cp $WORK_DIR \
-Djava.security.policy=${SUITE_DIR}/benchmark/bench/rmi/policy.all \
bench.rmi.Main \
-t $NHOURS \
-v \
-client localhost:2007 \
-c ${SUITE_DIR}/benchmark/bench/rmi/config \
> ${RES_DIR}/log.rmibench.client 2>&1
RETVAL=$?
echo " RMI benchmark test finished with exit value ${RETVAL}"
exit ${RETVAL}

View file

@ -0,0 +1,69 @@
#
# Copyright (c) 2005, 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.
#
#!/bin/ksh
#
# Script to build and launch the Serialization bench test as part of
# the RMI reliability test. This script is used to run
# the bench test for a certain number of hours. This
# script is NOT used when running the bench test as part
# of the jtreg regression suite.
WORK_DIR=$1
RES_DIR=$2
JAVA_HOME=$3
SUITE_DIR=$4
NHOURS=$5
shift 5
VMOPTS=$*
echo " ######### run_serialbench script ##########"
echo " WORK_DIR : $WORK_DIR "
echo " RES_DIR : $RES_DIR "
echo " JAVA_HOME : $JAVA_HOME "
echo " SUITE_DIR : $SUITE_DIR "
echo " NHOURS : $NHOURS "
echo " VMOPTS : $VMOPTS "
${JAVA_HOME}/bin/javac \
-d $WORK_DIR \
${SUITE_DIR}/benchmark/bench/serial/*.java \
${SUITE_DIR}/benchmark/bench/*.java
echo " Starting serialization benchmark "
${JAVA_HOME}/bin/java \
$VMOPTS \
-cp $WORK_DIR \
bench.serial.Main \
-t $NHOURS \
-v \
-c ${SUITE_DIR}/benchmark/bench/serial/config \
> ${RES_DIR}/log.serialbench 2>&1 &
RETVAL=$?
echo " Serialization benchmark test finished with exit value ${RETVAL}"
exit ${RETVAL}