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,140 @@
/*
* Copyright (c) 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.
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectInputFilter;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.rmi.MarshalledObject;
import java.util.Objects;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
/* @test
* @run testng/othervm MOFilterTest
*
* @summary Test MarshalledObject applies ObjectInputFilter
*/
@Test
public class MOFilterTest {
/**
* Two cases are tested.
* The filter = null and a filter set to verify the calls to the filter.
* @return array objects with test parameters for each test case
*/
@DataProvider(name = "FilterCases")
public static Object[][] filterCases() {
return new Object[][] {
{true}, // run the test with the filter
{false}, // run the test without the filter
};
}
/**
* Test that MarshalledObject inherits the ObjectInputFilter from
* the stream it was deserialized from.
*/
@Test(dataProvider="FilterCases")
static void delegatesToMO(boolean withFilter) {
try {
Serializable testobj = Integer.valueOf(5);
MarshalledObject<Serializable> mo = new MarshalledObject<>(testobj);
Assert.assertEquals(mo.get(), testobj, "MarshalledObject.get returned a non-equals test object");
byte[] bytes = writeObjects(mo);
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais)) {
CountingFilter filter1 = new CountingFilter();
ois.setObjectInputFilter(withFilter ? filter1 : null);
MarshalledObject<?> actualMO = (MarshalledObject<?>)ois.readObject();
int count = filter1.getCount();
actualMO.get();
int expectedCount = withFilter ? count + 2 : count;
int actualCount = filter1.getCount();
Assert.assertEquals(actualCount, expectedCount, "filter called wrong number of times during get()");
}
} catch (IOException ioe) {
Assert.fail("Unexpected IOException", ioe);
} catch (ClassNotFoundException cnf) {
Assert.fail("Deserializing", cnf);
}
}
/**
* Write objects and return a byte array with the bytes.
*
* @param objects zero or more objects to serialize
* @return the byte array of the serialized objects
* @throws IOException if an exception occurs
*/
static byte[] writeObjects(Object... objects) throws IOException {
byte[] bytes;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
for (Object o : objects) {
oos.writeObject(o);
}
bytes = baos.toByteArray();
}
return bytes;
}
static class CountingFilter implements ObjectInputFilter {
private int count; // count of calls to the filter
CountingFilter() {
count = 0;
}
int getCount() {
return count;
}
/**
* Filter that rejects class Integer and allows others
*
* @param filterInfo access to the class, arrayLength, etc.
* @return {@code STATUS.REJECTED}
*/
public ObjectInputFilter.Status checkInput(FilterInfo filterInfo) {
count++;
return ObjectInputFilter.Status.ALLOWED;
}
}
}

View file

@ -0,0 +1,108 @@
/*
* Copyright (c) 1998, 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.
*/
/*
* @test
* @bug 4096312
* @summary Codebase annotations on classes that are marshalled should not
* affect the behavior of MarshalledObject.equals. Only the bytes
* not involved in location should be compared.
* @author Ken Arnold
*
* @run main/othervm Compare 11 annotatedRef
*/
import java.rmi.MarshalledObject;
import java.io.*;
public class Compare {
static class Node implements Serializable {
int value = nextValue++;
Node next;
static int nextValue = 1;
};
private static MarshalledObject made;
private static MarshalledObject read;
public static void main(String[] args) throws Throwable {
if (args.length == 1)
writeObjToOut(Integer.parseInt(args[0]));
else
compareObjToFile(args[0], args[1]);
}
static void writeObjToOut(int listLength) throws Throwable {
ObjectOutputStream out = new ObjectOutputStream(System.out);
out.writeObject(marshalledList(listLength));
out.close();
}
public static void compareHashCodes(String[] args) throws Throwable {
File f = new File(System.getProperty("test.src", "."), args[1]);
setupObjects(args[0], f);
if (made.hashCode() != read.hashCode()) {
throw new RuntimeException(
"made.hashCode(){" + made.hashCode() + "} != " +
"read.hashCode(){" + read.hashCode() + "}"
);
}
}
static void compareObjToFile(String lengthStr, String file0) throws Throwable
{
File f = new File(System.getProperty("test.src", "."), file0);
setupObjects(lengthStr, f);
if (!made.equals(read) || !read.equals(made)) {
throw new RuntimeException(
"made.equals(read) = " + made.equals(read)
+ ", read.equals(made) = " + read.equals(made)
);
}
}
static MarshalledObject setupObjects(String lengthStr, File file)
throws Throwable
{
int listLength = Integer.parseInt(lengthStr);
made = marshalledList(listLength);
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
read = (MarshalledObject) in.readObject();
in.close();
return read;
}
static MarshalledObject marshalledList(int length) throws Throwable {
Node head = null;
Node cur = null;
for (int i = 0; i < length; i++) {
if (head == null)
cur = head = new Node();
else
cur = cur.next = new Node();
}
System.err.println("head = " + head);
return new MarshalledObject(head);
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 1998, 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.
*/
/*
* @test
* @bug 4105900
* @summary MarshalledObject with null throws NullPointerException
* @author Ken Arnold
*
* @run main/othervm HashCode 11 annotatedRef
*/
import java.rmi.MarshalledObject;
public class HashCode {
public static void main(String[] args) throws Throwable {
Compare.compareHashCodes(args);
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 1998, 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.
*/
/*
* @test
* @bug 4105900
* @summary MarshalledObject with null throws NullPointerException.
* This test does not affect VM global state, so othervm
* is not required.
* @author Ken Arnold
*
* @run main NullReference
*/
import java.rmi.MarshalledObject;
public class NullReference {
public static void main(String[] args) throws Throwable {
new MarshalledObject(null);
}
}

View file

@ -0,0 +1,2 @@
#!/bin/sh
java -Djava.rmi.server.codebase=http://jini.east Compare 11 > annotatedRef

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 1999, 2018, 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
* @bug 4251878
* @summary change in default URL port causes regression in java.rmi.Naming
* @author Dana Burns
* @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
* @run main/othervm DefaultRegistryPort
* @key intermittent
*/
/*
* Ensure that the default registry port for java.rmi.Naming URLs
* is 1099. Test creates a registry on port 1099 and then does a
* lookup with a Naming URL that uses the default port.
*/
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class DefaultRegistryPort {
public static void main(String args[]) throws Exception {
Registry registry = null;
System.err.println("Starting registry on default port REGISTRY_PORT="
+ Registry.REGISTRY_PORT);
final int NUM = 10;
for (int loop = 0; loop < NUM; loop++) {
System.err.println("in loop: " + loop);
try {
registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
System.err.println("Created registry=" + registry);
break;
} catch(java.rmi.RemoteException e) {
String err = e.getMessage();
if (err.contains("Address already in use")
|| err.contains("Port already in use")) {
try {
Thread.sleep((long)(TestLibrary.getTimeoutFactor() * 100));
} catch (InterruptedException ignore) { }
continue;
}
TestLibrary.bomb(e);
}
}
if (registry == null) {
throw new RuntimeException("can not create registry at "
+ Registry.REGISTRY_PORT + " after trying " + NUM + "times");
}
registry.rebind("myself", registry);
Remote myself = Naming.lookup("rmi://localhost/myself");
System.err.println("Test PASSED");
}
}

View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2001, 2018, 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 Ensure that java.rmi.Naming.lookup can handle URLs containing
* IPv6 addresses.
* @bug 4402708
* @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 RegistryVM
* @run main/othervm -Djava.net.preferIPv6Addresses=true LookupIPv6
*/
import java.io.Serializable;
import java.net.InetAddress;
import java.net.Inet6Address;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.Remote;
public class LookupIPv6 {
public static void main(String[] args) throws Exception {
// use loopback IPv6 address to avoid lengthy socket connection delays
String[] urls = {
"rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo",
"//[0:0:0:0:0:0:0:1]:88/foo",
"rmi://[0::0:0:0:1]/foo:bar",
"//[::1]:88"
};
for (int i = 0; i < urls.length; i++) {
try {
Naming.lookup(urls[i]);
} catch (MalformedURLException ex) {
throw ex;
} catch (Exception ex) {
// URLs are bogus, lookups expected to fail
}
}
/* Attempt to use IPv6-based URL to look up object in local registry.
* Since not all platforms support IPv6, this portion of the test may
* be a no-op in some cases. On supporting platforms, the first
* element of the array returned by InetAddress.getAllByName should be
* an Inet6Address since this test is run with
* -Djava.net.preferIPv6Addresses=true.
*/
InetAddress localAddr = InetAddress.getAllByName(null)[0];
if (localAddr instanceof Inet6Address) {
System.out.println("IPv6 detected");
RegistryVM rvm = RegistryVM.createRegistryVM();
try {
rvm.start();
String name = String.format("rmi://[%s]:%d/foo",
localAddr.getHostAddress(), rvm.getPort());
Naming.rebind(name, new R());
Naming.lookup(name);
} finally {
rvm.cleanup();
}
}
}
private static class R implements Remote, Serializable { }
}

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2001, 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
* @bug 4387038
* @summary Ensure that java.rmi.Naming.lookup functions properly for names
* containing embedded ':' characters.
*
* @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
* @run main/othervm LookupNameWithColon
*/
import java.rmi.Naming;
import java.rmi.registry.Registry;
public class LookupNameWithColon {
public static void main(String[] args) throws Exception {
String[] names = {
"fairly:simple", "somewhat:more/complicated",
"multiple:colons:in:name"
};
Registry reg = TestLibrary.createRegistryOnEphemeralPort();
int port = TestLibrary.getRegistryPort(reg);
for (int i = 0; i < names.length; i++) {
reg.rebind(names[i], reg);
Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
}
}
}

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2002, 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
* @bug 4626311
* @summary Protocol "rmi:" is used in contrary to spec. The Naming.list
* method should not append an "rmi:" scheme prefix to the URLs in the
* array of Strings it returns.
* @author Ann Wollrath
*
* @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
* @run main/othervm RmiIsNoScheme
*/
import java.io.*;
import java.rmi.*;
import java.rmi.registry.*;
public class RmiIsNoScheme implements Remote, Serializable {
private RmiIsNoScheme() {}
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4626311\n");
try {
Registry registry = TestLibrary.createRegistryOnEphemeralPort();
int registryPort = TestLibrary.getRegistryPort(registry);
Naming.rebind("//:" + registryPort + "/RmiIsNoScheme",
new RmiIsNoScheme());
String name = Naming.list("//:" + registryPort)[0];
System.err.println("name = " + name);
if (name.startsWith("rmi:", 0) == false) {
System.err.println("TEST PASSED: rmi scheme not present");
} else {
throw new RuntimeException("TEST FAILED: rmi scheme present!");
}
} catch (Exception e) {
TestLibrary.bomb(e);
}
}
}

View file

@ -0,0 +1,118 @@
/*
* Copyright (c) 2005, 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
* @bug 5083594
* @summary Ensure that Naming.java correctly parses host names with '_' in
* them.
* @author Vinod Johnson
*
* @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 UnderscoreHost_Stub
* @run main/othervm UnderscoreHost
*/
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.Socket;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RMISocketFactory;
import java.rmi.server.UnicastRemoteObject;
public class UnderscoreHost extends UnicastRemoteObject implements Remote {
private static final String HOSTNAME = "foo_bar";
private static final String NAME = "name";
/*
* The socket factory captures the host name of the parsed URL, and
* then connects to the local host.
*/
private static class HostVerifyingSocketFactory extends RMISocketFactory {
String host;
public synchronized Socket createSocket(String host, int port)
throws IOException {
if (this.host == null) {
// Only set it the first time, subsequent DGC dirty calls
// will be local host
this.host = host;
}
return new Socket("localhost", port);
}
public ServerSocket createServerSocket(int port) throws IOException {
return new ServerSocket(port);
}
}
public UnderscoreHost() throws RemoteException {};
public static void main(String args[]) {
UnderscoreHost t = null;
try {
HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
RMISocketFactory.setSocketFactory(hvf);
Registry r = TestLibrary.createRegistryOnEphemeralPort();
int port = TestLibrary.getRegistryPort(r);
t = new UnderscoreHost();
r.rebind(NAME, t);
Naming.lookup("rmi://" + HOSTNAME +
":" + port + "/" + NAME);
/*
* This test is coded to pass whether java.net.URI obeys
* RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
*
* If java.net.URI obeys RFC 3986, so host names may
* contain underscores, then the Naming.lookup invocation
* should succeed-- but the host actually connected to
* must equal HOSTNAME.
*/
if (!hvf.host.equals(HOSTNAME)) {
throw new RuntimeException(
"java.rmi.Naming Parsing error:" +
hvf.host + ":" + HOSTNAME);
}
} catch (MalformedURLException e) {
/*
* If java.net.URI obeys RFC 2396, so host names must not
* contain underscores, then the Naming.lookup invocation
* should throw MalformedURLException-- so this is OK.
*/
} catch (IOException ioe) {
TestLibrary.bomb(ioe);
} catch (java.rmi.NotBoundException nbe) {
TestLibrary.bomb(nbe);
} finally {
TestLibrary.unexport(t);
}
}
}

View file

@ -0,0 +1,38 @@
/*
* 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.
*/
// Stub class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class UnderscoreHost_Stub
extends java.rmi.server.RemoteStub
implements java.rmi.Remote
{
private static final long serialVersionUID = 2;
// constructors
public UnderscoreHost_Stub(java.rmi.server.RemoteRef ref) {
super(ref);
}
}

View file

@ -0,0 +1,28 @@
/*
* 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.
*/
/**
*
*/
import java.rmi.Remote;
public interface Legal extends Remote {};

View file

@ -0,0 +1,167 @@
/*
* 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
* @bug 4254808
* @summary Naming assumes '/' is present in relative URL; change in URL causes regression
* @author Dana Burns
* @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 Legal LegalRegistryNames_Stub
* @run main/othervm LegalRegistryNames
* @key intermittent
*/
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Enumeration;
import java.util.Vector;
/**
* Ensure that all legal forms of Naming URLs operate with the
* java.rmi.Naming interface. This test requires using the default RMI Registry
* port as it tests all of the RMI naming URL's, including the ones which do not
* take a port (and therefore uses the default port).
*/
public class LegalRegistryNames extends UnicastRemoteObject
implements Legal
{
public LegalRegistryNames() throws java.rmi.RemoteException {}
public static void main(String args[]) throws RuntimeException {
System.err.println("\nRegression test for bug/rfe 4254808\n");
Registry registry = null;
LegalRegistryNames legal = null;
boolean oneFormFailed = false;
String[] names = null;
Vector legalForms = getLegalForms();
Remote shouldFind = null;
// create a registry and the test object
try {
legal = new LegalRegistryNames();
System.err.println("Starting registry on default port");
registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
} catch (Exception e) {
TestLibrary.bomb("registry already running on test port");
}
// enumerate through all legal URLs to verify that a remote
// object can be bound and unbound
String s = null;
Enumeration en = legalForms.elements();
while (en.hasMoreElements()) {
s = (String) en.nextElement();
System.err.println("\ntesting form: " + s);
try {
Naming.rebind(s, legal);
names = registry.list();
// ensure that the name in the registry is what is expected
if ((names.length > 0) &&
(names[0].compareTo("MyName") != 0))
{
oneFormFailed = true;
System.err.println("\tRegistry entry for form: " +
s + " is incorrect: " + names[0]);
}
// ensure that the object can be unbound under the URL string
shouldFind = Naming.lookup(s);
Naming.unbind(s);
System.err.println("\tform " + s + " OK");
} catch (Exception e) {
e.printStackTrace();
oneFormFailed = true;
System.err.println("\tunexpected lookup or unbind " +
"exception for form: " + s + e.getMessage() );
}
}
if (oneFormFailed) {
TestLibrary.bomb("Test failed");
}
// get the test to exit quickly
TestLibrary.unexport(legal);
}
/**
* return a vector of valid legal RMI naming URLs.
*/
private static Vector getLegalForms() {
String localHostAddress = null;
String localHostName = null;
// get the local host name and address
try {
localHostName = InetAddress.getLocalHost().getHostName();
localHostAddress = InetAddress.getLocalHost().getHostAddress();
} catch(UnknownHostException e) {
TestLibrary.bomb("Test failed: unexpected exception", e);
}
Vector legalForms = new Vector();
legalForms.add("///MyName");
legalForms.add("//:" + Registry.REGISTRY_PORT + "/MyName");
legalForms.add("//" + localHostAddress + "/MyName");
legalForms.add("//" + localHostAddress + ":" +
Registry.REGISTRY_PORT + "/MyName");
legalForms.add("//localhost/MyName");
legalForms.add("//localhost:" + Registry.REGISTRY_PORT + "/MyName");
legalForms.add("//" + localHostName + "/MyName");
legalForms.add("//" + localHostName + ":" + Registry.REGISTRY_PORT +
"/MyName");
legalForms.add("MyName");
legalForms.add("/MyName");
legalForms.add("rmi:///MyName");
legalForms.add("rmi://:" + Registry.REGISTRY_PORT + "/MyName");
legalForms.add("rmi://" + localHostAddress + "/MyName");
legalForms.add("rmi://" + localHostAddress + ":" +
Registry.REGISTRY_PORT + "/MyName");
legalForms.add("rmi://localhost/MyName");
legalForms.add("rmi://localhost:" + Registry.REGISTRY_PORT + "/MyName");
legalForms.add("rmi://" + localHostName + "/MyName");
legalForms.add("rmi://" + localHostName + ":" +
Registry.REGISTRY_PORT + "/MyName");
return legalForms;
}
}

View file

@ -0,0 +1,38 @@
/*
* 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.
*/
// Stub class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class LegalRegistryNames_Stub
extends java.rmi.server.RemoteStub
implements java.rmi.Remote
{
private static final long serialVersionUID = 2;
// constructors
public LegalRegistryNames_Stub(java.rmi.server.RemoteRef ref) {
super(ref);
}
}

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2021, 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
* @bug 4416970
* @summary test chained exception support
* @run main/othervm Chaining
*/
import java.rmi.MarshalledObject;
import java.rmi.RemoteException;
import java.rmi.server.ServerCloneException;
public class Chaining {
static void check(Throwable t, String msg, Throwable cause)
throws Exception
{
String tmsg = t.getMessage();
if (msg == null ? tmsg != null : !msg.equals(tmsg)) {
throw new RuntimeException("message does not match");
}
if (t.getClass().getField("detail").get(t) != cause) {
throw new RuntimeException("detail field does not match");
}
if (t.getCause() != cause) {
throw new RuntimeException("getCause value does not match");
}
try {
t.initCause(cause);
throw new RuntimeException("initCause succeeded");
} catch (IllegalStateException e) {
}
}
static void test(Throwable t, String msg, Throwable cause)
throws Exception
{
check(t, msg, cause);
Throwable[] pair = new Throwable[]{t, cause};
pair = (Throwable[]) new MarshalledObject(pair).get();
check(pair[0], msg, pair[1]);
}
public static void main(String[] args) throws Exception {
Exception t = new RuntimeException();
String foo = "foo";
String fooMsg = "foo; nested exception is: \n\t" + t;
test(new RemoteException(), null, null);
test(new RemoteException(foo), foo, null);
test(new RemoteException(foo, t), fooMsg, t);
test(new ServerCloneException(foo), foo, null);
test(new ServerCloneException(foo, t), fooMsg, t);
}
}

View file

@ -0,0 +1 @@
modules = java.rmi

View file

@ -0,0 +1,60 @@
/*
* 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.
*/
/* @test
* @bug 4171370
* @summary VMIDs should be unique regardless of whether
* an IP address can be obtained. Instead of using an IP
* address in a VMID, a secure hash (using SHA) of the IP
* address is used.
* @author Ann Wollrath
*
* @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
* @run main/othervm -Djdk.net.hosts.file=nonExistentFile
* CheckVMID
*/
import java.rmi.dgc.VMID;
import java.net.InetAddress;
public class CheckVMID {
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4171370\n");
try {
System.err.println("Create a VMID");
VMID vmid = new VMID();
System.err.println("vmid = " + vmid);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("TEST FAILED: " + e.toString());
}
}
}

View file

@ -0,0 +1,198 @@
/*
* Copyright (c) 2001, 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
* @bug 4017232 8046339
* @summary If, after returning a reference to a remote object in the current
* VM (which gets implicitly converted to a remote stub), the client fails to
* both send a DGC dirty call and to send a "DGC acknowledgment", the RMI
* runtime should eventually allow the remote object to be garbage collected,
* rather than pinning it indefinitely.
* @author Peter Jones
*
* @modules java.rmi/sun.rmi.transport:+open
* @build DGCAckFailure DGCAckFailure_Stub
* @run main/othervm DGCAckFailure
*/
import java.io.*;
import java.net.*;
import java.lang.reflect.Field;
import java.lang.ref.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.Map;
import sun.rmi.transport.DGCAckHandler;
interface ReturnRemote extends Remote {
Object returnRemote() throws RemoteException;
}
public class DGCAckFailure implements ReturnRemote {
private static final long TIMEOUT = 20000;
private static final long ACK_TIMEOUT = TIMEOUT / 2;
public Object returnRemote() {
return new Wrapper(this);
}
public static void main(String[] args) throws Exception {
System.setProperty("sun.rmi.dgc.ackTimeout",
Long.toString(ACK_TIMEOUT));
/*
* Set a socket factory that has a hook for shutting down all client
* output (writes from client-created sockets and new connection
* attempts). We then use this hook right before a remote stub gets
* deserialized, so that the client will not be able to send a DGC
* dirty call, or a DGC acknowledgment. Without the DGC ack, we
* hope that the RMI runtime will still eventually allow the remote
* object to be garbage collected.
*/
RMISocketFactory.setSocketFactory(new TestSF());
System.err.println("test socket factory set");
Remote impl = new DGCAckFailure();
ReferenceQueue refQueue = new ReferenceQueue();
Reference weakRef = new WeakReference(impl, refQueue);
ReturnRemote stub =
(ReturnRemote) UnicastRemoteObject.exportObject(impl);
System.err.println("remote object exported; stub = " + stub);
try {
Object wrappedStub = stub.returnRemote();
System.err.println("invocation returned: " + wrappedStub);
impl = null;
stub = null; // in case 4114579 ever gets fixed
System.err.println("strong references to impl cleared");
System.err.println("waiting for weak reference notification:");
Reference ref = null;
for (int i = 0; i < 6; i++) {
System.gc();
ref = refQueue.remove(TIMEOUT / 5);
if (ref != null) {
break;
}
}
if (ref != weakRef) {
throw new RuntimeException("TEST FAILED: " +
"timed out, remote object not garbage collected");
}
// 8046339
// All DGCAckHandlers must be properly released after timeout
Thread.sleep(ACK_TIMEOUT + 100);
try {
Field field =
DGCAckHandler.class.getDeclaredField("idTable");
field.setAccessible(true);
Object obj = field.get(null);
Map<?,?> idTable = (Map<?,?>)obj;
if (!idTable.isEmpty()) {
throw new RuntimeException("TEST FAILED: " +
"DGCAckHandler.idTable isn't empty");
}
} catch (ReflectiveOperationException roe) {
throw new RuntimeException(roe);
}
System.err.println("TEST PASSED");
} finally {
try {
UnicastRemoteObject.unexportObject((Remote) weakRef.get(),
true);
} catch (Exception e) {
}
}
}
private static class Wrapper implements Serializable {
private final Remote obj;
Wrapper(Remote obj) { this.obj = obj; }
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
TestSF.shutdownClientOutput();
System.err.println(
"Wrapper.readObject: SHUTTING DOWN CLIENT OUTPUT");
in.defaultReadObject();
}
public String toString() { return "Wrapper[" + obj + "]"; }
}
private static class TestSF extends RMISocketFactory {
private static volatile boolean shutdown = false;
static void shutdownClientOutput() { shutdown = true; }
public Socket createSocket(String host, int port) throws IOException {
if (shutdown) {
IOException e = new java.net.ConnectException(
"test socket factory rejecting client connection");
System.err.println(e);
// e.printStackTrace();
throw e;
} else {
return new TestSocket(host, port);
}
}
public ServerSocket createServerSocket(int port) throws IOException {
return new ServerSocket(port);
}
private static class TestSocket extends Socket {
TestSocket(String host, int port) throws IOException {
super(host, port);
}
public OutputStream getOutputStream() throws IOException {
return new TestOutputStream(super.getOutputStream());
}
}
private static class TestOutputStream extends FilterOutputStream {
TestOutputStream(OutputStream out) { super(out); }
public void write(int b) throws IOException {
if (shutdown) {
IOException e = new IOException(
"connection broken by test socket factory");
System.err.println(e);
// e.printStackTrace();
throw e;
} else {
super.write(b);
}
}
}
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2001, 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.
*/
// Stub class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class DGCAckFailure_Stub
extends java.rmi.server.RemoteStub
implements ReturnRemote
{
private static final long serialVersionUID = 2;
private static java.lang.reflect.Method $method_returnRemote_0;
static {
try {
$method_returnRemote_0 = ReturnRemote.class.getMethod("returnRemote", new java.lang.Class[] {});
} catch (java.lang.NoSuchMethodException e) {
throw new java.lang.NoSuchMethodError(
"stub class initialization failed");
}
}
// constructors
public DGCAckFailure_Stub(java.rmi.server.RemoteRef ref) {
super(ref);
}
// methods from remote interfaces
// implementation of returnRemote()
public java.lang.Object returnRemote()
throws java.rmi.RemoteException
{
try {
Object $result = ref.invoke(this, $method_returnRemote_0, null, -8981544221566403070L);
return ((java.lang.Object) $result);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
}

View file

@ -0,0 +1,197 @@
/*
* Copyright (c) 1999, 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.
*/
/* @test
* @bug 4268258
* @summary When a DGC dirty call fails, RMI's client-side DGC implementation
* should attempt to retry the same dirty call a few times, at least until the
* known lease for that endpoint has expired, instead of just giving up
* renewing that lease at all after the first failure.
* @author Peter Jones (inspired by Adrian Colley's test case in 4268258)
*
* @build RetryDirtyCalls RetryDirtyCalls_Stub
* @run main/othervm RetryDirtyCalls
*/
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
interface Self extends Remote {
Self getSelf() throws RemoteException;
}
public class RetryDirtyCalls implements Self, Unreferenced {
/** how long we wait before declaring that this test has passed */
private final static long TIMEOUT = 20000;
/** true if this object's unreferenced method has been called */
private boolean unreferenced = false;
/**
* Return this object. The need for this method is explained below.
*/
public Self getSelf() {
return this;
}
public void unreferenced() {
synchronized (this) {
unreferenced = true;
notifyAll();
}
}
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4268258\n");
/*
* Set properties to tweak DGC behavior so that this test will execute
* quickly: set the granted lease duration to 10 seconds, the interval
* that leases are checked to 3 seconds.
*/
System.setProperty("java.rmi.dgc.leaseValue", "10000");
System.setProperty("sun.rmi.dgc.checkInterval", "3000");
/*
* Make idle connections time out almost instantly (0.1 seconds) so
* that the DGC implementation will have to make a new connection for
* each dirty call, thus going through the socket factory, where we
* can easily cause the operation to fail.
*/
System.setProperty("sun.rmi.transport.connectionTimeout", "100");
RetryDirtyCalls impl = new RetryDirtyCalls();
try {
TestSF sf = new TestSF();
RMISocketFactory.setSocketFactory(sf);
/*
* The stub returned by UnicastRemoteObject.exportObject() does
* not participate in DGC, but it does allow us to invoke a method
* on the remote object through RMI. Therefore, we invoke the
* getSelf() method through RMI, which returns an equivalent stub
* that does participate in DGC.
*/
Self stub = (Self) UnicastRemoteObject.exportObject(impl);
Self dgcStub = stub.getSelf();
stub = null; // in case 4114579 has been fixed
/*
* Set the socket factory to cause 3 connections attempts in a row
* to fail before allowing a connection to succeed, expecting the
* client-side DGC implementation to make at least four attempts.
*/
final int FLAKE_FACTOR = 3;
sf.setFlakeFactor(FLAKE_FACTOR);
long deadline = System.currentTimeMillis() + TIMEOUT;
boolean unreferenced;
synchronized (impl) {
while (!(unreferenced = impl.unreferenced)) {
long timeToWait = deadline - System.currentTimeMillis();
if (timeToWait > 0) {
impl.wait(timeToWait);
} else {
break;
}
}
}
if (unreferenced) {
throw new RuntimeException("remote object unreferenced");
}
int createCount = sf.getCreateCount();
if (createCount == 0) {
throw new RuntimeException("test socket factory never used");
} else if (createCount < (FLAKE_FACTOR + 3)) {
/*
* The unreferenced method was not invoked for some reason,
* but the dirty calls were clearly not retried well enough.
*/
throw new RuntimeException(
"test failed because dirty calls not retried enough, " +
"but remote object not unreferenced");
}
System.err.println(
"TEST PASSED: remote object not unreferenced");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("TEST FAILED: " + e.toString());
} finally {
/*
* When all is said and done, try to unexport the remote object
* so that the VM has a chance to exit.
*/
try {
UnicastRemoteObject.unexportObject(impl, true);
} catch (Exception e) {
}
}
}
}
class TestSF extends RMISocketFactory {
private int flakeFactor = 0;
private int flakeState = 0;
private int createCount = 0;
public synchronized void setFlakeFactor(int newFlakeFactor) {
flakeFactor = newFlakeFactor;
}
public synchronized int getCreateCount() {
return createCount;
}
public synchronized Socket createSocket(String host, int port)
throws IOException
{
createCount++;
if (++flakeState > flakeFactor) {
flakeState = 0;
}
if (flakeState == 0) {
return new Socket(host, port);
} else {
throw new IOException("random network failure");
}
}
public ServerSocket createServerSocket(int port) throws IOException {
return new ServerSocket(port);
}
}

View file

@ -0,0 +1,66 @@
/*
* 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.
*/
// Stub class generated by rmic, do not edit.
// Contents subject to change without notice.
public final class RetryDirtyCalls_Stub
extends java.rmi.server.RemoteStub
implements Self
{
private static final long serialVersionUID = 2;
private static java.lang.reflect.Method $method_getSelf_0;
static {
try {
$method_getSelf_0 = Self.class.getMethod("getSelf", new java.lang.Class[] {});
} catch (java.lang.NoSuchMethodException e) {
throw new java.lang.NoSuchMethodError(
"stub class initialization failed");
}
}
// constructors
public RetryDirtyCalls_Stub(java.rmi.server.RemoteRef ref) {
super(ref);
}
// methods from remote interfaces
// implementation of getSelf()
public Self getSelf()
throws java.rmi.RemoteException
{
try {
Object $result = ref.invoke(this, $method_getSelf_0, null, 2868857108246021904L);
return ((Self) $result);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
}

View file

@ -0,0 +1,99 @@
/*
* Copyright (c) 1998, 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.
*/
/* @test
* @bug 4136563
* @summary Naming.lookup fails to throw exception for invalid hostname
*
* @bug 4208801
* @summary (1.x) java.rmi.Naming defaults to local hostname, not
* local IP address
*
* @author Laird Dornin
*
* @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
* @run main/othervm InvalidName
*/
import java.net.URL;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.rmi.registry.Registry;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.server.RemoteObject;
import java.rmi.server.UnicastRemoteObject;
public class InvalidName {
public static void main(String[] args) {
String testName;
// ensure that an exception is thrown for Naming URL with '#'
try {
System.err.println("\nRegression test for bugs " +
"4136563 and 4208801\n");
testName = new String("rmi://#/MyRMI");
Naming.lookup(testName);
System.err.println("no exception thrown for URL: " + testName);
throw new RuntimeException("test failed");
} catch (MalformedURLException e) {
// should have received malformed URL exception
System.err.println("Correctly received instance of " +
"MalformedURLException:");
System.err.println(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
TestLibrary.bomb(e);
}
// ensure a correct null pointer exception is thrown for null URL
// ensure that a registry stub with a default hostname and one with a
// the local host's ip address are .equals()
try {
String localAddress = InetAddress.getLocalHost().getHostAddress();
Registry registry = (Registry) Naming.lookup("rmi:///");
if (registry.toString().indexOf(localAddress) >= 0) {
System.err.println("verified registry endpoint contains ipaddress");
} else {
TestLibrary.bomb("registry endpoint does not contain ipaddress");
}
} catch (Exception e) {
TestLibrary.bomb(e);
}
System.err.println("test passed");
}
}

View file

@ -0,0 +1,163 @@
/*
* Copyright (c) 2016, 2021, 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
* @library /test/lib
* @build jdk.test.lib.process.ProcessTools
* jdk.test.lib.compiler.CompilerUtils
* jdk.test.lib.util.JarUtils
* ModuleTest
* @run testng ModuleTest
* @summary Basic tests for using rmi in module world
*/
import static jdk.test.lib.process.ProcessTools.executeTestJava;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.io.File;
import java.nio.file.Paths;
import jdk.test.lib.compiler.CompilerUtils;
import jdk.test.lib.util.JarUtils;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ModuleTest {
static String fileJoin(String... names) {
return String.join(File.separator, names);
}
static String pathJoin(String... paths) {
return String.join(File.pathSeparator, paths);
}
private static final String TEST_SRC = System.getProperty("test.src");
private static final String CLIENT_EXP = fileJoin("exploded", "mclient");
private static final String SERVER_EXP = fileJoin("exploded", "mserver");
private static final String MTEST_EXP = fileJoin("exploded", "mtest");
private static final String CLIENT_JAR = fileJoin("mods", "mclient.jar");
private static final String SERVER_JAR = fileJoin("mods", "mserver.jar");
private static final String MTEST_JAR = fileJoin("mods", "mtest.jar");
private static final String DUMMY_MAIN = "testpkg.DummyApp";
/**
* Compiles all sample classes
*/
@BeforeTest
public void compileAll() throws Exception {
assertTrue(CompilerUtils.compile(
Paths.get(TEST_SRC, "src", "mserver"),
Paths.get(SERVER_EXP)));
JarUtils.createJarFile(
Paths.get(SERVER_JAR),
Paths.get(SERVER_EXP));
assertTrue(CompilerUtils.compile(
Paths.get(TEST_SRC, "src", "mclient"),
Paths.get(CLIENT_EXP),
"-cp", SERVER_JAR));
JarUtils.createJarFile(
Paths.get(CLIENT_JAR),
Paths.get(CLIENT_EXP));
assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "mtest"),
Paths.get(MTEST_EXP),
"-cp", pathJoin(CLIENT_JAR, SERVER_JAR)));
JarUtils.createJarFile(
Paths.get(MTEST_JAR),
Paths.get(MTEST_EXP));
}
/**
* Test the client, server and dummy application in different modules
* @throws Exception
*/
@Test
public void testAllInModule() throws Exception {
assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, CLIENT_JAR, SERVER_JAR),
"--add-modules", "mclient,mserver",
"-m", "mtest/" + DUMMY_MAIN)
.outputTo(System.out)
.errorTo(System.out)
.getExitValue(),
0);
}
/**
* Test the client and server in unnamed modules,
* while the dummy application is in automatic module
* @throws Exception
*/
@Test
public void testAppInModule() throws Exception {
assertEquals(executeTestJava("--module-path", MTEST_JAR,
"-cp", pathJoin(CLIENT_JAR, SERVER_JAR),
"-m", "mtest/" + DUMMY_MAIN)
.outputTo(System.out)
.errorTo(System.out)
.getExitValue(),
0);
}
/**
* Test the client and server in automatic modules,
* while the dummy application is in unnamed module
* @throws Exception
*/
@Test
public void testAppInUnnamedModule() throws Exception {
assertEquals(executeTestJava("--module-path", pathJoin(CLIENT_JAR, SERVER_JAR),
"--add-modules", "mclient,mserver",
"-cp", MTEST_JAR,
DUMMY_MAIN)
.outputTo(System.out)
.errorTo(System.out)
.getExitValue(),
0);
}
/**
* Test the server and test application in automatic modules,
* with client in unnamed module
* @throws Exception
*/
@Test
public void testClientInUnnamedModule() throws Exception {
assertEquals(executeTestJava("--module-path", pathJoin(MTEST_JAR, SERVER_JAR),
"--add-modules", "mserver",
"-cp", CLIENT_JAR,
"-m", "mtest/" + DUMMY_MAIN)
.outputTo(System.out)
.errorTo(System.out)
.getExitValue(),
0);
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 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.
*/
package clientpkg;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import serverpkg.Hello;
public class Client {
int port;
Hello stub;
public Client(Hello stub) {
this.stub = stub;
}
public String testStub() throws Exception {
try {
return stub.sayHello();
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
throw e;
}
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 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.
*/
package serverpkg;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 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.
*/
package serverpkg;
public class Server implements Hello {
private final String hello = "Hello world!";
public Server() {
}
@Override
public String sayHello() {
return hello;
}
}

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 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.
*/
package testpkg;
import java.rmi.server.UnicastRemoteObject;
import clientpkg.Client;
import serverpkg.Hello;
import serverpkg.Server;
public class DummyApp {
public static void main(String args[]) {
try {
Hello obj = new Server();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
Client client = new Client(stub);
String testStubReturn = client.testStub();
System.out.println("Stub is: " + testStubReturn);
if (!testStubReturn.equals(obj.sayHello())) {
throw new RuntimeException("Unexpected string from stub call, expected \""
+ testStubReturn + "\", actual \"" + obj.sayHello() + "\"");
} else {
System.out.println("Test passed");
}
System.exit(0);
} catch (Throwable e) {
e.printStackTrace();
System.exit(-1);
}
}
}

View file

@ -0,0 +1,167 @@
/*
* 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.
*/
/* @test
* @bug 4242317
* @summary When a class that can be found in the CLASSPATH of the rmiregistry
* tool is marshalled via RMI, it should be annotated with the value of the
* java.rmi.server.codebase property, not the list of "file:" URLs for the
* actual elements of the CLASSPATH.
* @author Peter Jones
*
* @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 Dummy RegistryVM RMIRegistryRunner TestLoaderHandler
* @run main/othervm
* -Djava.rmi.server.useCodebaseOnly=false ClassPathCodebase
*/
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.Arrays;
public class ClassPathCodebase {
/** wait dozens of seconds for the registry process to be ready to call */
private static final long REGISTRY_WAIT =
(long)(10000 * TestLibrary.getTimeoutFactor());
private final static String dummyClassName = "Dummy";
private final static String dummyBinding = "DummyObject";
private final static String importCodebase = "codebase_IMPORT_";
private final static String exportCodebase = "codebase_EXPORT_";
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4242317\n");
System.setProperty("java.rmi.server.RMIClassLoaderSpi", "TestLoaderHandler");
RegistryVM rmiregistry = null;
try {
/*
* Install a dummy class in two codebases: one that will be in
* the rmiregistry's CLASSPATH (the "import" codebase) and one
* that will be in the rmiregistry's "java.rmi.server.codebase"
* property (the "export" codebase).
*/
URL importCodebaseURL = TestLibrary.installClassInCodebase(
dummyClassName, importCodebase, false);
URL exportCodebaseURL = TestLibrary.installClassInCodebase(
dummyClassName, exportCodebase, true);
/*
* Spawn an rmiregistry in the "import" codebase directory.
*/
File rmiregistryDir =
new File(System.getProperty("user.dir", "."), importCodebase);
rmiregistry = RegistryVM.createRegistryVMWithRunner("RMIRegistryRunner",
" -Denv.class.path=."
+ " -Djava.rmi.server.codebase=" + exportCodebaseURL
+ " -Duser.dir=" + rmiregistryDir.getAbsolutePath());
rmiregistry.start();
int port = rmiregistry.getPort();
/*
* Wait for the registry to initialize and be ready to call.
*/
Thread.sleep(REGISTRY_WAIT);
System.err.println();
/*
* Create an instance of the dummy class, finding it from the
* "import" codebase.
*/
ClassLoader loader = URLClassLoader.newInstance(
new URL[] { importCodebaseURL });
Class dummyClass = Class.forName(dummyClassName, false, loader);
Remote dummyObject = (Remote) dummyClass.newInstance();
/*
* Find the registry that we created and bind the
* dummy object to it.
*/
Registry registry = LocateRegistry.getRegistry(
"localhost", port);
try {
registry.bind(dummyBinding, dummyObject);
System.err.println("Bound dummy object in registry");
} catch (java.rmi.ConnectException e) {
System.err.println("Error: rmiregistry not started in time");
throw e;
} catch (ServerException e) {
if (e.detail instanceof UnmarshalException &&
((UnmarshalException) e.detail).detail instanceof
ClassNotFoundException)
{
System.err.println(
"Error: another registry running on port " +
port + "?");
}
throw e;
}
/*
* Look up the dummy object from our registry and make sure
* that its class was annotated with the "export" codebase.
*/
Remote dummyLookup = registry.lookup(dummyBinding);
System.err.println(
"Looked up dummy object from registry: " + dummyLookup);
Class dummyLookupClass = dummyLookup.getClass();
String dummyLookupAnnotation =
RMIClassLoader.getClassAnnotation(dummyLookupClass);
System.err.println(
"Class annotation from registry: " + dummyLookupAnnotation);
System.err.println();
if (dummyLookupAnnotation.indexOf(exportCodebase) >= 0) {
System.err.println("TEST PASSED");
} else if (dummyLookupAnnotation.indexOf(importCodebase) >= 0) {
throw new RuntimeException(
"rmiregistry annotated with CLASSPATH element URL");
} else {
throw new RuntimeException(
"rmiregistry used unexpected annotation: \"" +
dummyLookupAnnotation + "\"");
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("TEST FAILED: " + e.toString());
} finally {
if (rmiregistry != null) {
rmiregistry.cleanup();
}
}
}
}

View file

@ -0,0 +1,47 @@
/*
* 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.
*/
/*
* Dummy implements Remote so that it can be stored in the registry,
* extends RemoteStub so that it can be marshalled without having a
* corresponding stub, and implements Externalizable so that
* RemoteObject will not complain about being marshalled with a
* null RemoteRef.
*/
public class Dummy
extends java.rmi.server.RemoteStub
implements java.rmi.Remote, java.io.Externalizable
{
public Dummy() {
}
public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
{
}
public void readExternal(java.io.ObjectInput in)
throws java.io.IOException, ClassNotFoundException
{
}
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2000, 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
* @bug 4399304
* @summary check that registry allows empty names
* @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
* @run main/othervm EmptyName
*/
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RemoteObject;
public class EmptyName {
public static void main(String[] args) throws Exception {
Registry impl = TestLibrary.createRegistryOnEphemeralPort();
Registry stub = (Registry) RemoteObject.toStub(impl);
stub.bind("", stub);
stub.lookup("");
stub.rebind("", stub);
stub.lookup("");
stub.unbind("");
}
}

View file

@ -0,0 +1,222 @@
/*
* Copyright (c) 2001, 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
* @bug 4472769
* @summary Stubs and skeletons used to implement the RMI registry
* implementation and the bootstrap stubs must always follow certain
* "well known" protocols so that they otherwise need not be in sync--
* in other words, a registry stub from any arbitrary J2SE vendor and
* version must be able to communicate with a registry skeleton from
* any other arbitrary J2SE vendor and version. In addition to
* (unfortunately) using the old "-v1.1" stub/skeleton invocation
* protocol, with its unevolvable operation number scheme, they must
* always use the same value for the -v1.1 stub/skeleton
* "interface hash": 4905912898345647071L.
*
* @author Peter Jones
* @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 ReferenceRegistryStub
* @run main/othervm InterfaceHash
*/
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.rmi.Remote;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.ObjID;
import java.rmi.server.Operation;
import java.rmi.server.RemoteCall;
import java.rmi.server.RemoteObject;
import java.rmi.server.RemoteRef;
import java.util.Arrays;
import sun.rmi.server.UnicastRef;
import sun.rmi.transport.LiveRef;
import sun.rmi.transport.tcp.TCPEndpoint;
public class InterfaceHash {
private static final String NAME = "WMM";
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 4472769");
System.err.println(
"\n=== verifying that J2SE registry's skeleton uses" +
"\ncorrect interface hash and operation numbers:");
Registry testImpl = TestLibrary.createRegistryOnEphemeralPort();
int regPort = TestLibrary.getRegistryPort(testImpl);
System.err.println("created test registry on port " + regPort);
RemoteRef ref = new UnicastRef(
new LiveRef(new ObjID(ObjID.REGISTRY_ID),
new TCPEndpoint("", regPort), false));
Registry referenceStub = new ReferenceRegistryStub(ref);
System.err.println("created reference registry stub: " +
referenceStub);
referenceStub.bind(NAME, referenceStub);
System.err.println("bound name \"" + NAME + "\" in registry");
String[] list = referenceStub.list();
System.err.println("list of registry contents: " +
Arrays.asList(list));
if (list.length != 1 || !list[0].equals(NAME)) {
throw new RuntimeException(
"TEST FAILED: unexpected list contents");
}
Registry result = (Registry) referenceStub.lookup(NAME);
System.err.println("lookup of name \"" + NAME + "\" returned: " +
result);
if (!result.equals(referenceStub)) {
throw new RuntimeException(
"TEST FAILED: unexpected lookup result");
}
referenceStub.rebind(NAME, referenceStub);
referenceStub.unbind(NAME);
System.err.println("unbound name \"" + NAME + "\"");
list = referenceStub.list();
System.err.println("list of registry contents: " +
Arrays.asList(list));
if (list.length != 0) {
throw new RuntimeException("TEST FAILED: list not empty");
}
System.err.println("\n=== verifying that J2SE registry's stub uses" +
"correct interface hash:");
class FakeRemoteRef implements RemoteRef {
long hash;
int opnum;
public RemoteCall newCall(RemoteObject obj, Operation[] op,
int opnum, long hash)
{
this.hash = hash;
this.opnum = opnum;
throw new UnsupportedOperationException();
}
public void invoke(RemoteCall call) { }
public void done(RemoteCall call) { }
public Object invoke(Remote obj, Method method,
Object[] args, long hash)
{
throw new UnsupportedOperationException();
}
public String getRefClass(java.io.ObjectOutput out) {
return "FakeRemoteRef";
}
public int remoteHashCode() { return 1013; }
public boolean remoteEquals(RemoteRef obj) { return false; }
public String remoteToString() { return "FakeRemoteRef"; }
public void writeExternal(java.io.ObjectOutput out) { }
public void readExternal(java.io.ObjectInput in) { }
}
FakeRemoteRef f = new FakeRemoteRef();
Registry testRegistry = LocateRegistry.getRegistry(regPort);
System.err.println("created original test registry stub: " +
testRegistry);
Class stubClass = testRegistry.getClass();
System.err.println("test registry stub class: " + stubClass);
Constructor cons = stubClass.getConstructor(
new Class[] { RemoteRef.class });
Registry testStub = (Registry) cons.newInstance(
new Object[] { f });
System.err.println("created new instrumented test registry stub: " +
testStub);
System.err.println("invoking bind:");
try {
testStub.bind(NAME, referenceStub);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 0) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking list:");
try {
testStub.list();
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 1) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking lookup:");
try {
testStub.lookup(NAME);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 2) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking rebind:");
try {
testStub.rebind(NAME, referenceStub);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 3) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking unbind:");
try {
testStub.unbind(NAME);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 4) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("TEST PASSED");
}
}

View file

@ -0,0 +1,186 @@
/*
* Copyright (c) 2001, 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.
*/
public final class ReferenceRegistryStub
extends java.rmi.server.RemoteStub
implements java.rmi.registry.Registry, java.rmi.Remote
{
private static final java.rmi.server.Operation[] operations = {
new java.rmi.server.Operation("void bind(java.lang.String, java.rmi.Remote)"),
new java.rmi.server.Operation("java.lang.String list()[]"),
new java.rmi.server.Operation("java.rmi.Remote lookup(java.lang.String)"),
new java.rmi.server.Operation("void rebind(java.lang.String, java.rmi.Remote)"),
new java.rmi.server.Operation("void unbind(java.lang.String)")
};
private static final long interfaceHash = 4905912898345647071L;
// constructors
public ReferenceRegistryStub() {
super();
}
public ReferenceRegistryStub(java.rmi.server.RemoteRef ref) {
super(ref);
}
// methods from remote interfaces
// implementation of bind(String, Remote)
public void bind(java.lang.String $param_String_1, java.rmi.Remote $param_Remote_2)
throws java.rmi.AccessException, java.rmi.AlreadyBoundException, java.rmi.RemoteException
{
try {
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 0, interfaceHash);
try {
java.io.ObjectOutput out = call.getOutputStream();
out.writeObject($param_String_1);
out.writeObject($param_Remote_2);
} catch (java.io.IOException e) {
throw new java.rmi.MarshalException("error marshalling arguments", e);
}
ref.invoke(call);
ref.done(call);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (java.rmi.AlreadyBoundException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
// implementation of list()
public java.lang.String[] list()
throws java.rmi.AccessException, java.rmi.RemoteException
{
try {
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 1, interfaceHash);
ref.invoke(call);
java.lang.String[] $result;
try {
java.io.ObjectInput in = call.getInputStream();
$result = (java.lang.String[]) in.readObject();
} catch (java.io.IOException e) {
throw new java.rmi.UnmarshalException("error unmarshalling return", e);
} catch (java.lang.ClassNotFoundException e) {
throw new java.rmi.UnmarshalException("error unmarshalling return", e);
} finally {
ref.done(call);
}
return $result;
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
// implementation of lookup(String)
public java.rmi.Remote lookup(java.lang.String $param_String_1)
throws java.rmi.AccessException, java.rmi.NotBoundException, java.rmi.RemoteException
{
try {
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 2, interfaceHash);
try {
java.io.ObjectOutput out = call.getOutputStream();
out.writeObject($param_String_1);
} catch (java.io.IOException e) {
throw new java.rmi.MarshalException("error marshalling arguments", e);
}
ref.invoke(call);
java.rmi.Remote $result;
try {
java.io.ObjectInput in = call.getInputStream();
$result = (java.rmi.Remote) in.readObject();
} catch (java.io.IOException e) {
throw new java.rmi.UnmarshalException("error unmarshalling return", e);
} catch (java.lang.ClassNotFoundException e) {
throw new java.rmi.UnmarshalException("error unmarshalling return", e);
} finally {
ref.done(call);
}
return $result;
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (java.rmi.NotBoundException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
// implementation of rebind(String, Remote)
public void rebind(java.lang.String $param_String_1, java.rmi.Remote $param_Remote_2)
throws java.rmi.AccessException, java.rmi.RemoteException
{
try {
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 3, interfaceHash);
try {
java.io.ObjectOutput out = call.getOutputStream();
out.writeObject($param_String_1);
out.writeObject($param_Remote_2);
} catch (java.io.IOException e) {
throw new java.rmi.MarshalException("error marshalling arguments", e);
}
ref.invoke(call);
ref.done(call);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
// implementation of unbind(String)
public void unbind(java.lang.String $param_String_1)
throws java.rmi.AccessException, java.rmi.NotBoundException, java.rmi.RemoteException
{
try {
java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject) this, operations, 4, interfaceHash);
try {
java.io.ObjectOutput out = call.getOutputStream();
out.writeObject($param_String_1);
} catch (java.io.IOException e) {
throw new java.rmi.MarshalException("error marshalling arguments", e);
}
ref.invoke(call);
ref.done(call);
} catch (java.lang.RuntimeException e) {
throw e;
} catch (java.rmi.RemoteException e) {
throw e;
} catch (java.rmi.NotBoundException e) {
throw e;
} catch (java.lang.Exception e) {
throw new java.rmi.UnexpectedException("undeclared checked exception", e);
}
}
}

View file

@ -0,0 +1,99 @@
/*
* 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.
*/
/* @test
* @bug 4267864
* @summary Can't run multiple registries in the same VM
* @author Ann Wollrath
*
* @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
* @run main/othervm/timeout=240 MultipleRegistries
*/
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class MultipleRegistries implements RemoteInterface {
private static final String NAME = "MultipleRegistries";
public Object passObject(Object obj) {
return obj;
}
public static void main(String[] args) throws Exception {
RemoteInterface server = null;
RemoteInterface proxy = null;
try {
System.err.println("export object");
server = new MultipleRegistries();
proxy =
(RemoteInterface) UnicastRemoteObject.exportObject(server, 0);
System.err.println("proxy = " + proxy);
System.err.println("export registries");
Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
int port1 = TestLibrary.getRegistryPort(registryImpl1);
Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
int port2 = TestLibrary.getRegistryPort(registryImpl2);
System.err.println("bind remote object in registries");
Registry registry1 = LocateRegistry.getRegistry(port1);
Registry registry2 = LocateRegistry.getRegistry(port2);
registry1.bind(NAME, proxy);
registry2.bind(NAME, proxy);
System.err.println("lookup remote object in registries");
RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);
System.err.println("invoke methods on remote objects");
remote1.passObject(remote1);
remote2.passObject(remote2);
System.err.println("TEST PASSED");
} finally {
if (proxy != null) {
UnicastRemoteObject.unexportObject(server, true);
}
}
}
}
interface RemoteInterface extends Remote {
Object passObject(Object obj) throws RemoteException;
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2017, 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.net.InetAddress;
import java.rmi.AccessException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Set;
/* @test
* @bug 8174770
* @summary Verify that Registry rejects non-local access for bind, unbind, rebind.
* The test is manual because the (non-local) host running rmiregistry must be supplied as a property.
* @run main/othervm/manual -Dregistry.host=rmi-registry-host NonLocalRegistryTest
*/
/**
* Verify that access checks for Registry.bind(), .rebind(), and .unbind()
* are prevented on remote access to the registry.
*
* This test is a manual test and uses a standard rmiregistry running
* on a *different* host.
* The test verifies that the access check is performed *before* the object to be
* bound or rebound is deserialized.
*
* Login or ssh to the different host and invoke {@code $JDK_HOME/bin/rmiregistry}.
* It will not show any output.
*
* On the first host modify the @run command above to replace "rmi-registry-host"
* with the hostname or IP address of the different host and run the test with jtreg.
*/
public class NonLocalRegistryTest {
public static void main(String[] args) throws Exception {
String host = System.getProperty("registry.host");
if (host == null || host.isEmpty()) {
throw new RuntimeException("Specify host with system property: -Dregistry.host=<host>");
}
// Check if running the test on a local system; it only applies to remote
String myHostName = InetAddress.getLocalHost().getHostName();
Set<InetAddress> myAddrs = Set.of(InetAddress.getAllByName(myHostName));
Set<InetAddress> hostAddrs = Set.of(InetAddress.getAllByName(host));
if (hostAddrs.stream().anyMatch(i -> myAddrs.contains(i))
|| hostAddrs.stream().anyMatch(h -> h.isLoopbackAddress())) {
throw new RuntimeException("Error: property 'registry.host' must not be the local host%n");
}
Registry registry = LocateRegistry.getRegistry(host, Registry.REGISTRY_PORT);
try {
registry.bind("foo", null);
throw new RuntimeException("Remote access should not succeed for method: bind");
} catch (Exception e) {
assertIsAccessException(e);
}
try {
registry.rebind("foo", null);
throw new RuntimeException("Remote access should not succeed for method: rebind");
} catch (Exception e) {
assertIsAccessException(e);
}
try {
registry.unbind("foo");
throw new RuntimeException("Remote access should not succeed for method: unbind");
} catch (Exception e) {
assertIsAccessException(e);
}
}
/**
* Check the exception chain for the expected AccessException and message.
* @param ex the exception from the remote invocation.
*/
private static void assertIsAccessException(Throwable ex) {
Throwable t = ex;
while (!(t instanceof AccessException) && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof AccessException) {
String msg = t.getMessage();
int asIndex = msg.indexOf("Registry");
int rrIndex = msg.indexOf("Registry.Registry"); // Obsolete error text
int disallowIndex = msg.indexOf("disallowed");
int nonLocalHostIndex = msg.indexOf("non-local host");
if (asIndex < 0 ||
rrIndex != -1 ||
disallowIndex < 0 ||
nonLocalHostIndex < 0 ) {
throw new RuntimeException("exception message is malformed", t);
}
System.out.printf("Found expected AccessException: %s%n%n", t);
} else {
throw new RuntimeException("AccessException did not occur when expected", ex);
}
}
}

View file

@ -0,0 +1,172 @@
/*
* Copyright (c) 2017, 2019, 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 sun.rmi.server.UnicastRef;
import sun.rmi.transport.LiveRef;
import sun.rmi.transport.tcp.TCPEndpoint;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.net.InetAddress;
import java.rmi.AccessException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.ObjID;
import java.rmi.server.RemoteObjectInvocationHandler;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.Set;
/* @test
* @bug 8218453
* @library ../../testlibrary
* @modules java.rmi/sun.rmi.registry:+open java.rmi/sun.rmi.server:+open
* java.rmi/sun.rmi.transport:+open java.rmi/sun.rmi.transport.tcp:+open
* @summary Verify that Registry rejects non-local access for bind, unbind, rebind.
* The test is manual because the (non-local) host running rmiregistry must be supplied as a property.
* @run main/othervm -Dregistry.host=localhost NonLocalSkeletonTest
*/
/*
* @test
* @library ../../testlibrary
* @modules java.rmi/sun.rmi.registry:+open java.rmi/sun.rmi.server:+open
* java.rmi/sun.rmi.transport:+open java.rmi/sun.rmi.transport.tcp:+open
* @summary Verify that Registry rejects non-local access for bind, unbind, rebind.
* The test is manual because the (non-local) host running rmiregistry must be supplied as a property.
* @run main/othervm/manual -Dregistry.host=rmi-registry-host NonLocalSkeletonTest
*/
/**
* Verify that access checks for Registry.bind(), .rebind(), and .unbind()
* are prevented on remote access to the registry.
*
* This test is a manual test and uses a standard rmiregistry running
* on a *different* host.
* The test verifies that the access check is performed *before* the object to be
* bound or rebound is deserialized.
*
* Login or ssh to the different host and invoke {@code $JDK_HOME/bin/rmiregistry}.
* It will not show any output.
*
* On the first host modify the @run command above to replace "rmi-registry-host"
* with the hostname or IP address of the different host and run the test with jtreg.
*/
public class NonLocalSkeletonTest {
public static void main(String[] args) throws Exception {
String host = System.getProperty("registry.host");
if (host == null || host.isEmpty()) {
throw new RuntimeException("supply a remote host with -Dregistry.host=hostname");
}
// Check if running the test on a local system; it only applies to remote
String myHostName = InetAddress.getLocalHost().getHostName();
Set<InetAddress> myAddrs = Set.copyOf(Arrays.asList(InetAddress.getAllByName(myHostName)));
Set<InetAddress> hostAddrs = Set.copyOf(Arrays.asList(InetAddress.getAllByName(host)));
boolean isLocal = (hostAddrs.stream().anyMatch(i -> myAddrs.contains(i))
|| hostAddrs.stream().anyMatch(h -> h.isLoopbackAddress()));
int port;
if (isLocal) {
// Create a local Registry to use for the test
port = TestLibrary.getUnusedRandomPort();
Registry registry = LocateRegistry.createRegistry(port);
System.out.printf("local registry port: %s%n", registry);
} else {
// Use regular rmi registry for non-local test
port = Registry.REGISTRY_PORT;
}
try {
Registry r = nonStaticRegistryProxy(host, port);
System.out.printf("RegistryRef: %s%n", r);
r.rebind("anyRef", r);
if (!isLocal) {
throw new RuntimeException("non-local bind should have failed to host: " + host);
} else {
System.out.printf("local rebind succeeded%n");
}
} catch (RemoteException rex) {
if (!isLocal) {
assertIsAccessException(rex);
} else {
throw rex;
}
}
}
/* Returns a non-static proxy for the registry.
* Follows the form of sun.rmi.server.Util.createProxy.
* @param implClass the RegistryImpl
* @param clientRef the registry reference
**/
static Registry nonStaticRegistryProxy(String host, int port) {
final ClassLoader loader = Registry.class.getClassLoader();
final Class<?>[] interfaces = new Class<?>[]{Registry.class};
LiveRef liveRef = new LiveRef(new ObjID(ObjID.REGISTRY_ID),
new TCPEndpoint(host, port, null, null),
false);
final InvocationHandler handler = new RemoteObjectInvocationHandler(new UnicastRef(liveRef));
PrivilegedAction<Registry> action = () -> (Registry) Proxy.newProxyInstance(loader,
interfaces, handler);
return AccessController.doPrivileged(action);
}
/**
* Check the exception chain for the expected AccessException and message.
* @param ex the exception from the remote invocation.
*/
private static void assertIsAccessException(Throwable ex) {
Throwable t = ex;
while (!(t instanceof AccessException) && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof AccessException) {
String msg = t.getMessage();
int asIndex = msg.indexOf("Registry");
int rrIndex = msg.indexOf("Registry.Registry"); // Obsolete error text
int disallowIndex = msg.indexOf("disallowed");
int nonLocalHostIndex = msg.indexOf("non-local host");
if (asIndex < 0 ||
rrIndex != -1 ||
disallowIndex < 0 ||
nonLocalHostIndex < 0 ) {
throw new RuntimeException("exception message is malformed", t);
}
System.out.printf("Found expected AccessException: %s%n%n", t);
} else {
throw new RuntimeException("AccessException did not occur when expected", ex);
}
}
}

View file

@ -0,0 +1,91 @@
/*
* Copyright (c) 2017, 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
* @bug 7102369 7094468 7100592
* @modules java.rmi/sun.rmi.registry
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @library ../../testlibrary
* @build TestLibrary RMIRegistryRunner RegistryVM JavaVM testPkg.* RegistryLookup TestLoaderHandler
* @summary remove java.rmi.server.codebase property parsing from registyimpl
* @run main/othervm CodebaseTest
*/
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
public class CodebaseTest {
public static void main(String args[]) throws Exception {
RegistryVM rmiregistry = null;
JavaVM client = null;
System.setProperty("java.rmi.server.RMIClassLoaderSpi", "TestLoaderHandler");
try {
File src = new File(System.getProperty("test.classes", "."), "testPkg");
File dest = new File(System.getProperty("user.dir", "."), "testPkg");
Files.move(src.toPath(), dest.toPath(),
StandardCopyOption.REPLACE_EXISTING);
File rmiregistryDir =
new File(System.getProperty("user.dir", "."), "rmi_tmp");
rmiregistryDir.mkdirs();
rmiregistry = RegistryVM.createRegistryVMWithRunner(
"RMIRegistryRunner",
" -Djava.rmi.server.useCodebaseOnly=false"
+ " -Duser.dir=" + rmiregistryDir.getAbsolutePath()
+ " -Djava.rmi.server.RMIClassLoaderSpi=TestLoaderHandler");
rmiregistry.start();
int port = rmiregistry.getPort();
File srcReadTest = new File(System.getProperty("test.classes", "."),
"RegistryLookup.class");
File destReadTest = new File(System.getProperty("user.dir", "."),
"RegistryLookup.class");
Files.move(srcReadTest.toPath(), destReadTest.toPath(),
StandardCopyOption.REPLACE_EXISTING);
File codebase = new File(System.getProperty("user.dir", "."));
client = new JavaVM("RegistryLookup",
" -Djava.rmi.server.codebase=" + codebase.toURI().toURL()
+ " -cp ." + File.pathSeparator + System.getProperty("test.class.path")
+ " -Djava.rmi.server.RMIClassLoaderSpi=TestLoaderHandler",
Integer.toString(port));
int exit = client.execute();
if (exit == RegistryLookup.EXIT_FAIL) {
throw new RuntimeException("Test Fails");
}
} finally {
if (rmiregistry != null) {
rmiregistry.cleanup();
}
if (client != null) {
client.cleanup();
}
}
}
}

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2011, 2017, 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.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class RegistryLookup {
public static final int EXIT_FAIL = 1;
public static void main(String args[]) throws Exception {
Registry registry = null;
int exit = 0;
try {
int port = Integer.valueOf(args[0]);
testPkg.Server obj = new testPkg.Server();
testPkg.Hello stub =
(testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
registry = LocateRegistry.getRegistry(port);
registry.bind("Hello", stub);
System.err.println("Server ready");
testPkg.Client client = new testPkg.Client(port);
String testStubReturn = client.testStub();
if(!testStubReturn.equals(obj.hello)) {
throw new RuntimeException("Test Fails : "
+ "unexpected string from stub call");
}
registry.unbind("Hello");
System.out.println("Test passed");
} catch (Exception ex) {
exit = EXIT_FAIL;
ex.printStackTrace();
}
// need to exit explicitly, and parent process uses exit value
// to tell if the test passed.
System.exit(exit);
}
}

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2011, 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 testPkg;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
int port;
public Client(int p) {
port = p;
}
public String testStub() throws Exception {
try {
Registry registry = LocateRegistry.getRegistry(port);
Hello stub = (Hello) registry.lookup("Hello");
String response = stub.sayHello();
return response;
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
throw e;
}
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2011, 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 testPkg;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2011, 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 testPkg;
public class Server implements Hello {
public String hello = "Hello, world!";
public Server() {}
public String sayHello() {
return hello;
}
}

View file

@ -0,0 +1,105 @@
/*
* Copyright (c) 1999, 2018, 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
* @bug 4120329
* @summary RMI registry creation is impossible if first attempt fails.
* @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
* @run main/othervm Reexport
*/
/*
* If a VM could not create an RMI registry because the registry port
* was already occupied by this or other processes, the next
* time the VM tried to create a registry (after the other registry
* was brought down) the attempt would fail. The second try to create
* a registry would fail because the registry ObjID would still be in
* use when it should never have been allocated.
*
* The test creates this conflict starting a dummy tcp server and ensures
* that a registry can still be created after the conflict is resolved.
*/
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Reexport {
static public void main(String[] argv) throws IOException {
for (int loop = 0; loop < 10; loop++) {
System.err.println("\nat loop: " + loop);
int port = -1;
try (ServerSocketChannel server = ServerSocketChannel.open();) {
server.bind(null);
InetSocketAddress addr = (InetSocketAddress)server.getLocalAddress();
port = addr.getPort();
System.err.println("Creating duplicate registry, this should fail...");
createReg(port, true);
}
try {
if (createReg(port, false) == null) {
TestLibrary.bomb("Could not create registry on second try");
}
System.err.println("Test passed");
return;
} catch (Exception e) {
String err = e.getMessage();
if (err.contains("Address already in use")
|| err.contains("Port already in use")) {
continue;
}
TestLibrary.bomb(e);
}
}
TestLibrary.bomb("Test failed");
}
static Registry createReg(int port, boolean expectException) {
Registry reg = null;
try {
reg = LocateRegistry.createRegistry(port);
if (expectException) {
TestLibrary.bomb("Registry is up, an Exception is expected!");
}
} catch (Throwable e) {
if (expectException) {
System.err.println("EXPECTING PORT IN USE EXCEPTION:");
System.err.println(e.getMessage());
e.printStackTrace();
} else {
TestLibrary.bomb((Exception) e);
}
}
return reg;
}
}

View file

@ -0,0 +1,236 @@
/*
* Copyright (c) 2016, 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.
*/
import java.io.IOException;
import java.io.Serializable;
import java.rmi.AlreadyBoundException;
import java.rmi.MarshalledObject;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.security.Security;
import java.util.Objects;
import org.testng.Assert;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @test
* @library /java/rmi/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
* @summary Test filters for the RMI Registry
* @run testng/othervm RegistryFilterTest
* @run testng/othervm
* -Dsun.rmi.registry.registryFilter=!java.lang.Long;!RegistryFilterTest$RejectableClass;maxdepth=19
* -Dtest.maxdepth=19
* RegistryFilterTest
* @run testng/othervm
* -Djava.security.properties=${test.src}/java.security-extra1
* RegistryFilterTest
*/
public class RegistryFilterTest {
private static Registry impl;
private static int port;
private static Registry registry;
static final int REGISTRY_MAX_DEPTH = 20;
static final int REGISTRY_MAX_ARRAY = 1_000_000;
static final String registryFilter =
System.getProperty("sun.rmi.registry.registryFilter",
Security.getProperty("sun.rmi.registry.registryFilter"));
/**
* Data RMI Registry bind test.
* - name
* - Object
* - true/false if object is blacklisted by a filter (implicit or explicit)
* @return array of test data
*/
@DataProvider(name = "bindData")
static Object[][] bindObjects() {
Object[][] data = {
{ "byte[max]", new XX(new byte[REGISTRY_MAX_ARRAY]), false },
{ "String", new XX("now is the time"), false},
{ "String[3]", new XX(new String[3]), false},
{ "Long[4]", new XX(new Long[4]), false },
{ "Object[REGISTRY_MAX_ARRAY]", new XX(new Object[REGISTRY_MAX_ARRAY]), false },
{ "rej-byte[toobig]", new XX(new byte[REGISTRY_MAX_ARRAY + 1]), true },
{ "rej-Object[toobig]", new XX(new Object[REGISTRY_MAX_ARRAY + 1]), true },
{ "rej-MarshalledObject", createMarshalledObject(), true },
{ "rej-RejectableClass", new RejectableClass(), registryFilter != null},
};
return data;
}
static XX createMarshalledObject() {
try {
return new XX(new MarshalledObject<>(null));
} catch (IOException ioe) {
return new XX(ioe);
}
}
@BeforeSuite
static void setupRegistry() {
try {
impl = TestLibrary.createRegistryOnEphemeralPort();
port = TestLibrary.getRegistryPort(impl);
registry = LocateRegistry.getRegistry("localhost", port);
} catch (RemoteException ex) {
Assert.fail("initialization of registry", ex);
}
System.out.printf("RMI Registry filter: %s%n", registryFilter);
}
/*
* Test registry rejects an object with the max array size + 1.
*/
@Test(dataProvider="bindData")
public void simpleBind(String name, Remote obj, boolean blacklisted) throws RemoteException, AlreadyBoundException, NotBoundException {
try {
registry.bind(name, obj);
Assert.assertFalse(blacklisted, "Registry filter did not reject (but should have) ");
registry.unbind(name);
} catch (Exception rex) {
Assert.assertTrue(blacklisted, "Registry filter should not have rejected");
}
}
/*
* Test registry rejects an object with a well known class
* if blacklisted in the security properties.
*/
@Test
public void simpleRejectableClass() throws RemoteException, AlreadyBoundException, NotBoundException {
RejectableClass r1 = null;
try {
String name = "reject1";
r1 = new RejectableClass();
registry.bind(name, r1);
registry.unbind(name);
Assert.assertNull(registryFilter, "Registry filter should have rejected");
} catch (Exception rex) {
Assert.assertNotNull(registryFilter, "Registry filter should not have rejected");
}
}
/*
* Test registry does not reject an object with depth at the built-in limit.
*/
@Test
public void simpleDepthBuiltinNonRejectable() throws RemoteException, AlreadyBoundException, NotBoundException {
int depthOverride = Integer.getInteger("test.maxdepth", REGISTRY_MAX_DEPTH);
depthOverride = Math.min(depthOverride, REGISTRY_MAX_DEPTH);
System.out.printf("overrideDepth: %d, filter: %s%n", depthOverride, registryFilter);
try {
String name = "reject2";
DepthRejectableClass r1 = DepthRejectableClass.create(depthOverride);
registry.bind(name, r1);
registry.unbind(name);
} catch (Exception rex) {
Assert.fail("Registry filter should not have rejected depth: "
+ depthOverride);
}
}
/*
* Test registry rejects an object with depth at the limit + 1.
*/
@Test
public void simpleDepthRejectable() throws RemoteException, AlreadyBoundException, NotBoundException {
int depthOverride = Integer.getInteger("test.maxdepth", REGISTRY_MAX_DEPTH);
depthOverride = Math.min(depthOverride, REGISTRY_MAX_DEPTH);
System.out.printf("overrideDepth: %d, filter: %s%n", depthOverride, registryFilter);
try {
String name = "reject3";
DepthRejectableClass r1 = DepthRejectableClass.create(depthOverride + 1);
registry.bind(name, r1);
Assert.fail("Registry filter should have rejected depth: " + depthOverride + 1);
} catch (Exception rex) {
// Rejection expected
}
}
/**
* A simple Serializable Remote object that is passed by value.
* It and its contents are checked by the Registry serial filter.
*/
static class XX implements Serializable, Remote {
private static final long serialVersionUID = 362498820763181265L;
final Object obj;
XX(Object obj) {
this.obj = obj;
}
public String toString() {
return super.toString() + "//" + Objects.toString(obj);
}
}
/**
* A simple Serializable Remote object that is passed by value.
* It and its contents are checked by the Registry serial filter.
*/
static class RejectableClass implements Serializable, Remote {
private static final long serialVersionUID = 362498820763181264L;
RejectableClass() {}
}
/**
* A simple Serializable Remote object that is passed by value.
* It and its contents are checked by the Registry serial filter.
*/
static class DepthRejectableClass implements Serializable, Remote {
private static final long serialVersionUID = 362498820763181264L;
private final DepthRejectableClass next;
private DepthRejectableClass(DepthRejectableClass next) {
this.next = next;
}
static DepthRejectableClass create(int depth) {
DepthRejectableClass next = new DepthRejectableClass(null);
for (int i = 1; i < depth; i++) {
next = new DepthRejectableClass(next);
}
return next;
}
}
}

View file

@ -0,0 +1,2 @@
# disabled till JDK-8219408 is fixed
allowSmartActionArgs=false

View file

@ -0,0 +1,9 @@
# RMI Registry Input Serial Filter
#
# The filter pattern uses the same format as java.io.ObjectInputStream.serialFilter.
# This filter can override the builtin filter if additional types need to be
# allowed or rejected from the RMI Registry.
#
#sun.rmi.registry.registryFilter=pattern,pattern
sun.rmi.registry.registryFilter=!java.lang.Long;!RegistryFilterTest$RejectableClass

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();
}
}
}
}

Some files were not shown because too many files have changed in this diff Show more