8085192: java/rmi/activation/Activatable tests fail intermittently due to "Port already in use"
Reviewed-by: rriggs, mli
--- a/jdk/src/java.rmi/share/classes/sun/rmi/server/Activation.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/src/java.rmi/share/classes/sun/rmi/server/Activation.java Tue Oct 25 10:31:49 2016 +0100
@@ -1970,6 +1970,11 @@
AccessController.doPrivileged(
new PrivilegedExceptionAction<Void>() {
public Void run() throws IOException {
+ boolean disable = Boolean.getBoolean(
+ "sun.rmi.server.activation.disableErrRedirect");
+ if (disable)
+ return null;
+
File file =
Files.createTempFile("rmid-err", null).toFile();
PrintStream errStream =
--- a/jdk/test/java/rmi/activation/Activatable/checkActivateRef/CheckActivateRef.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkActivateRef/CheckActivateRef.java Tue Oct 25 10:31:49 2016 +0100
@@ -40,7 +40,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivateMe CheckActivateRef_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivateMe CheckActivateRef_Stub
* @run main/othervm/policy=security.policy/timeout=240 -Djava.rmi.server.ignoreStubClasses=true CheckActivateRef
* @run main/othervm/policy=security.policy/timeout=240 -Djava.rmi.server.ignoreStubClasses=false CheckActivateRef
* @key intermittent
@@ -118,7 +119,7 @@
// start an rmid.
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/checkActivateRef/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkActivateRef/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -2,4 +2,6 @@
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.rmi.server.useDynamicProxies=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/checkActivateRef/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkActivateRef/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -38,4 +38,6 @@
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "getClassLoader";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/checkAnnotations/CheckAnnotations.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkAnnotations/CheckAnnotations.java Tue Oct 25 10:31:49 2016 +0100
@@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID MyRMI CheckAnnotations_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider MyRMI CheckAnnotations_Stub
* @run main/othervm/policy=security.policy/timeout=480 CheckAnnotations
*/
@@ -77,7 +78,7 @@
// start an rmid.
RMID.removeLog();
- rmid = RMID.createRMID(rmidOut, rmidErr, false);
+ rmid = RMID.createRMIDOnEphemeralPort(rmidOut, rmidErr, false);
rmid.start();
/* Cause activation groups to have a security policy that will
@@ -228,6 +229,7 @@
return false;
}
+
// just make sure that last two strings are what we expect.
if (execOut.equals("ExecGroup-" + iteration)
&& (new String(destOut.substring(0,4)).equals("out" +
--- a/jdk/test/java/rmi/activation/Activatable/checkAnnotations/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkAnnotations/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/checkAnnotations/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkAnnotations/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -28,4 +28,7 @@
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/CheckImplClassLoader.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/CheckImplClassLoader.java Tue Oct 25 10:31:49 2016 +0100
@@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider
* MyRMI ActivatableImpl ActivatableImpl ActivatableImpl_Stub
* @run main/othervm/policy=security.policy/timeout=150 CheckImplClassLoader
*/
@@ -80,7 +81,7 @@
TestParams.defaultSecurityManager);
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
System.err.println("Create activation group in this VM");
--- a/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -39,4 +39,7 @@
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/CheckRegisterInLog.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/CheckRegisterInLog.java Tue Oct 25 10:31:49 2016 +0100
@@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe CheckRegisterInLog_Stub
* @run main/othervm/policy=security.policy/timeout=240 CheckRegisterInLog
*/
@@ -99,7 +100,7 @@
* Start up activation system daemon "rmid".
*/
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -31,4 +31,7 @@
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/CreatePrivateActivatable.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/CreatePrivateActivatable.java Tue Oct 25 10:31:49 2016 +0100
@@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivateMe
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivateMe
* @run main/othervm/policy=security.policy/timeout=240 CreatePrivateActivatable
*/
@@ -103,7 +104,7 @@
// start an rmid.
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -31,4 +31,7 @@
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/DownloadParameterClass.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/DownloadParameterClass.java Tue Oct 25 10:31:49 2016 +0100
@@ -35,7 +35,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* Foo FooReceiverImpl FooReceiverImpl_Stub Bar
* @run main/othervm/policy=security.policy/timeout=240 DownloadParameterClass
*/
@@ -90,7 +91,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/manual.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/manual.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -34,4 +34,7 @@
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -35,4 +35,7 @@
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/ElucidateNoSuchMethod.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/ElucidateNoSuchMethod.java Tue Oct 25 10:31:49 2016 +0100
@@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivateMe ElucidateNoSuchMethod_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivateMe ElucidateNoSuchMethod_Stub
* @run main/othervm/policy=security.policy/timeout=240 ElucidateNoSuchMethod
*/
@@ -91,7 +92,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,7 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -37,4 +37,7 @@
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/extLoadedImpl/ExtLoadedImplTest.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/extLoadedImpl/ExtLoadedImplTest.java Tue Oct 25 10:31:49 2016 +0100
@@ -37,7 +37,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
Properties p = new Properties();
p.put("java.security.policy",
--- a/jdk/test/java/rmi/activation/Activatable/extLoadedImpl/ext.sh Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/extLoadedImpl/ext.sh Tue Oct 25 10:31:49 2016 +0100
@@ -27,7 +27,7 @@
# loader, the context class loader should remain unchanged (i.e., not be
# set to the impl's class loader) when the impl is activated.
# @library ../../../testlibrary
-# @build TestLibrary RMID ActivationLibrary
+# @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
# @build ExtLoadedImplTest ExtLoadedImpl ExtLoadedImpl_Stub CheckLoader
# @run shell ext.sh
--- a/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/ForceLogSnapshot.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/ForceLogSnapshot.java Tue Oct 25 10:31:49 2016 +0100
@@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe ForceLogSnapshot_Stub
* @run main/othervm/policy=security.policy/timeout=640 ForceLogSnapshot
*/
@@ -129,7 +130,7 @@
SNAPSHOT_INTERVAL;
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.addOptions(new String[] {option, "-Djava.compiler="});
rmid.start();
--- a/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -31,4 +31,7 @@
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/inactiveGroup/InactiveGroup.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/inactiveGroup/InactiveGroup.java Tue Oct 25 10:31:49 2016 +0100
@@ -33,7 +33,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary ActivateMe InactiveGroup_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe InactiveGroup_Stub
* @run main/othervm/policy=security.policy/timeout=240 InactiveGroup
*/
@@ -101,7 +102,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/inactiveGroup/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/inactiveGroup/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/inactiveGroup/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/inactiveGroup/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -31,4 +31,7 @@
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java Tue Oct 25 10:31:49 2016 +0100
@@ -33,7 +33,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* @run main/othervm/timeout=240 LookupActivationSystem
*/
@@ -55,7 +56,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
System.err.println("look up activation system");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/rmi/activation/Activatable/lookupActivationSystem/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -0,0 +1,4 @@
+grant {
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
+};
--- a/jdk/test/java/rmi/activation/Activatable/nestedActivate/NestedActivate.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/nestedActivate/NestedActivate.java Tue Oct 25 10:31:49 2016 +0100
@@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary ActivateMe NestedActivate_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe NestedActivate_Stub
* @run main/othervm/policy=security.policy/timeout=240 NestedActivate
*/
@@ -101,7 +102,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/nestedActivate/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/nestedActivate/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/nestedActivate/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/nestedActivate/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -31,4 +31,7 @@
// allow exporting of non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/NonExistentActivatable.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/NonExistentActivatable.java Tue Oct 25 10:31:49 2016 +0100
@@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe NonExistentActivatable_Stub
* @run main/othervm/policy=security.policy/timeout=240 NonExistentActivatable
*/
@@ -91,7 +92,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -32,4 +32,6 @@
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/restartCrashedService/RestartCrashedService.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartCrashedService/RestartCrashedService.java Tue Oct 25 10:31:49 2016 +0100
@@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivateMe RestartCrashedService_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivateMe RestartCrashedService_Stub
* @run main/othervm/policy=security.policy/timeout=240 RestartCrashedService
*/
@@ -119,7 +120,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/restartCrashedService/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartCrashedService/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/restartCrashedService/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartCrashedService/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -28,4 +28,7 @@
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartLatecomer/RestartLatecomer.java Tue Oct 25 10:31:49 2016 +0100
@@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* RestartLatecomer RestartLatecomer_Stub
* @run main/othervm/policy=security.policy/timeout=240 RestartLatecomer
*/
@@ -166,7 +167,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/restartLatecomer/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartLatecomer/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/restartLatecomer/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartLatecomer/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -33,4 +33,7 @@
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/restartService/RestartService.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartService/RestartService.java Tue Oct 25 10:31:49 2016 +0100
@@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary ActivateMe RestartService_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe RestartService_Stub
* @run main/othervm/policy=security.policy/timeout=240 RestartService
*/
@@ -129,7 +130,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/Activatable/restartService/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartService/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/restartService/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/restartService/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -33,4 +33,7 @@
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/ShutdownGracefully.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/ShutdownGracefully.java Tue Oct 25 10:31:49 2016 +0100
@@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider
* TestSecurityManager RegisteringActivatable ShutdownGracefully_Stub
* @run main/othervm/policy=security.policy/timeout=700 ShutdownGracefully
*/
@@ -76,7 +77,7 @@
// start an rmid.
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
// rmid needs to run with a security manager that
// simulates a log problem; rmid should also snapshot
--- a/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -2,4 +2,6 @@
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=java.lang.SecurityManager";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission com.sun.rmi.rmid.ExecOptionPermission "-Ddummyname=dummyvalue";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -25,4 +25,7 @@
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/unregisterInactive/UnregisterInactive.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/unregisterInactive/UnregisterInactive.java Tue Oct 25 10:31:49 2016 +0100
@@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary ActivateMe UnregisterInactive_Stub
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe UnregisterInactive_Stub
* @run main/othervm/policy=security.policy/timeout=240 UnregisterInactive
*/
@@ -89,7 +90,7 @@
try {
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
System.err.println("Creating descriptor");
--- a/jdk/test/java/rmi/activation/Activatable/unregisterInactive/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/unregisterInactive/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/Activatable/unregisterInactive/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/Activatable/unregisterInactive/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -28,4 +28,7 @@
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/ActivateFails.java Tue Oct 25 10:31:49 2016 +0100
@@ -35,7 +35,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary RMID ActivationLibrary
+ * java.base/sun.nio.ch
+ * @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe ActivateFails_Stub ShutdownThread
* @run main/othervm/java.security.policy=security.policy/timeout=240 ActivateFails
*/
@@ -93,7 +94,7 @@
* First run "rmid" and wait for it to start up.
*/
RMID.removeLog();
- rmid = RMID.createRMID();
+ rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/rmid.security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/rmid.security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy Tue Oct 25 10:31:49 2016 +0100
@@ -28,4 +28,7 @@
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+ permission java.lang.RuntimePermission "selectorProvider";
+ permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};
--- a/jdk/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java Tue Oct 25 10:31:49 2016 +0100
@@ -51,6 +51,8 @@
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
+import static java.net.StandardSocketOptions.SO_REUSEADDR;
+import static java.net.StandardSocketOptions.SO_REUSEPORT;
public class RmidViaInheritedChannel implements Callback {
private static final Object lock = new Object();
@@ -185,6 +187,15 @@
*/
channel = ServerSocketChannel.open();
ServerSocket serverSocket = channel.socket();
+
+ // Enable SO_REUSEADDR before binding
+ serverSocket.setOption(SO_REUSEADDR, true);
+
+ // Enable SO_REUSEPORT, if supported, before binding
+ if (serverSocket.supportedOptions().contains(SO_REUSEPORT)) {
+ serverSocket.setOption(SO_REUSEPORT, true);
+ }
+
serverSocket.bind(
new InetSocketAddress(InetAddress.getLocalHost(),
TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
--- a/jdk/test/java/rmi/testlibrary/JavaVM.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/testlibrary/JavaVM.java Tue Oct 25 10:31:49 2016 +0100
@@ -21,8 +21,11 @@
* questions.
*/
+import java.io.BufferedReader;
+import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.StringTokenizer;
@@ -39,8 +42,8 @@
protected Process vm = null;
private String classname = "";
- private String args = "";
- private String options = "";
+ protected String args = "";
+ protected String options = "";
private OutputStream outputStream = System.out;
private OutputStream errorStream = System.err;
private String policyFileName = null;
@@ -113,7 +116,7 @@
/**
* Exec the VM as specified in this object's constructor.
*/
- public void start() throws IOException {
+ private void start0() throws IOException {
if (vm != null)
throw new IllegalStateException("JavaVM already started");
@@ -152,12 +155,50 @@
mesg("command = " + Arrays.asList(javaCommand).toString());
vm = Runtime.getRuntime().exec(javaCommand);
+ }
- /* output from the execed process may optionally be captured. */
+ public void start() throws IOException {
+ start0();
+
+ /* output from the exec'ed process may optionally be captured. */
outPipe = StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
errPipe = StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
}
+ public int startAndGetPort() throws IOException {
+ start0();
+
+ int port = -1;
+ if (options.contains("java.nio.channels.spi.SelectorProvider=RMIDSelectorProvider")) {
+ // Obtain the server socket channel's ephemeral port number of the
+ // child rmid process.
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(vm.getInputStream()));
+ String s;
+ while ((s = reader.readLine()) != null) {
+ System.out.println(s);
+ int i = s.indexOf(RMID.EPHEMERAL_MSG);
+ if (i != -1) {
+ String v = s.substring(RMID.EPHEMERAL_MSG.length());
+ port = Integer.valueOf(v);
+ break;
+ }
+ }
+ if (port == -1) {
+ // something failed
+ reader = new BufferedReader(new InputStreamReader(vm.getErrorStream()));
+ while ((s = reader.readLine()) != null)
+ System.err.println(s);
+ }
+ }
+
+ /* output from the exec'ed process may optionally be captured. */
+ outPipe = StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
+ errPipe = StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
+
+ return port;
+ }
+
public void destroy() {
if (vm != null) {
vm.destroy();
--- a/jdk/test/java/rmi/testlibrary/RMID.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/testlibrary/RMID.java Tue Oct 25 10:31:49 2016 +0100
@@ -49,20 +49,31 @@
public static String MANAGER_OPTION="-Djava.security.manager=";
- /** Test port for rmid */
- private final int port;
+ /**
+ * Test port for rmid.
+ *
+ * May initially be 0, which means that the child rmid process will choose
+ * an ephemeral port and report it back to the parent process. This field
+ * will then be set to the child rmid's ephemeral port value.
+ */
+ private volatile int port;
+ //private final boolean ephemeralPort
/** Initial log name */
protected static String log = "log";
/** rmid's logfile directory; currently must be "." */
protected static String LOGDIR = ".";
+ /** The output message from the child rmid process that directly precedes
+ * the ephemeral port number.*/
+ public static final String EPHEMERAL_MSG = "RmidSelectorProvider-listening-On:";
+
private static void mesg(Object mesg) {
System.err.println("RMID: " + mesg.toString());
}
/** make test options and arguments */
- private static String makeOptions(boolean debugExec) {
+ private static String makeOptions(int port, boolean debugExec) {
String options = " -Dsun.rmi.server.activation.debugExec=" +
debugExec;
@@ -87,6 +98,17 @@
// to avoid spurious timeouts on slow machines.
options += " -Dsun.rmi.activation.execTimeout=60000";
+ if (port == 0) {
+ // Ephemeral port, so have the rmid child process create the
+ // server socket channel and report its port number, over stdin.
+ options += " -classpath " + TestParams.testClassPath;
+ options += " --add-exports=java.base/sun.nio.ch=ALL-UNNAMED";
+ options += " -Djava.nio.channels.spi.SelectorProvider=RMIDSelectorProvider";
+
+ // Disable redirection of System.err to /tmp
+ options += " -Dsun.rmi.server.activation.disableErrRedirect=true";
+ }
+
return options;
}
@@ -107,7 +129,8 @@
String args =
" -log " + (new File(LOGDIR, log)).getAbsolutePath();
- if (includePortArg) {
+ // 0 = ephemeral port, do not include an explicit port number
+ if (includePortArg && port != 0) {
args += " -port " + port;
}
@@ -160,7 +183,7 @@
boolean debugExec, boolean includePortArg,
int port)
{
- String options = makeOptions(debugExec);
+ String options = makeOptions(port, debugExec);
String args = makeArgs(includePortArg, port);
RMID rmid = new RMID("sun.rmi.server.Activation", options, args,
out, err, port);
@@ -169,6 +192,17 @@
return rmid;
}
+ public static RMID createRMIDOnEphemeralPort() {
+ return createRMID(System.out, System.err, true, true, 0);
+ }
+
+ public static RMID createRMIDOnEphemeralPort(OutputStream out,
+ OutputStream err,
+ boolean debugExec)
+ {
+ return createRMID(out, err, debugExec, true, 0);
+ }
+
/**
* Private constructor. RMID instances should be created
@@ -247,7 +281,10 @@
// a well recognized exception (port already in use...).
mesg("Starting rmid on port " + port + ".");
- super.start();
+ int p = super.startAndGetPort();
+ if (p != -1)
+ port = p;
+ mesg("Started rmid on port " + port + ".");
// int slopFactor = 1;
// try {
@@ -271,8 +308,11 @@
try {
int status = vm.exitValue();
+ waitFor(TIMEOUT_SHUTDOWN_MS);
TestLibrary.bomb("Rmid process exited with status " + status + " after " +
(System.currentTimeMillis() - startTime) + "ms.");
+ } catch (InterruptedException | TimeoutException e) {
+ mesg(e);
} catch (IllegalThreadStateException ignore) { }
// The rmid process is alive; check to see whether
@@ -307,6 +347,8 @@
*/
public void restart() throws IOException {
destroy();
+ options = makeOptions(port, true);
+ args = makeArgs(true, port);
start();
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/rmi/testlibrary/RMIDSelectorProvider.java Tue Oct 25 10:31:49 2016 +0100
@@ -0,0 +1,107 @@
+/*
+ * 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.*;
+import java.net.InetSocketAddress;
+import java.net.ProtocolFamily;
+import java.nio.channels.Channel;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.Pipe;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.AbstractSelector;
+import java.nio.channels.spi.SelectorProvider;
+import static java.net.StandardSocketOptions.SO_REUSEADDR;
+import static java.net.StandardSocketOptions.SO_REUSEPORT;
+
+/**
+ * A SelectorProvider, that can be loaded by the child rmid process, whose
+ * inheritedChannel method will create a new server socket channel and report
+ * it back to the parent process, over stdout.
+ */
+public class RMIDSelectorProvider extends SelectorProvider {
+
+ private final SelectorProvider provider;
+ private ServerSocketChannel channel;
+
+ public RMIDSelectorProvider() {
+ provider = sun.nio.ch.DefaultSelectorProvider.create();
+ }
+
+ public DatagramChannel openDatagramChannel()
+ throws IOException
+ {
+ return provider.openDatagramChannel();
+ }
+
+ public DatagramChannel openDatagramChannel(ProtocolFamily family)
+ throws IOException
+ {
+ return provider.openDatagramChannel(family);
+ }
+
+ public Pipe openPipe()
+ throws IOException
+ {
+ return provider.openPipe();
+ }
+
+ public AbstractSelector openSelector()
+ throws IOException
+ {
+ return provider.openSelector();
+ }
+
+ public ServerSocketChannel openServerSocketChannel()
+ throws IOException
+ {
+ return provider.openServerSocketChannel();
+ }
+
+ public SocketChannel openSocketChannel()
+ throws IOException
+ {
+ return provider.openSocketChannel();
+ }
+
+ public synchronized Channel inheritedChannel() throws IOException {
+ System.out.println("RMIDSelectorProvider.inheritedChannel");
+ if (channel == null) {
+ // Create and bind a new server socket channel
+ channel = ServerSocketChannel.open();
+
+ // Enable SO_REUSEADDR before binding
+ channel.setOption(SO_REUSEADDR, true);
+
+ // Enable SO_REUSEPORT, if supported, before binding
+ if (channel.supportedOptions().contains(SO_REUSEPORT)) {
+ channel.setOption(SO_REUSEPORT, true);
+ }
+
+ channel.bind(new InetSocketAddress(0));
+
+ System.out.println(RMID.EPHEMERAL_MSG + channel.socket().getLocalPort());
+ }
+ return channel;
+ }
+}
--- a/jdk/test/java/rmi/testlibrary/TestParams.java Tue Oct 25 15:43:19 2016 +0900
+++ b/jdk/test/java/rmi/testlibrary/TestParams.java Tue Oct 25 10:31:49 2016 +0100
@@ -34,6 +34,7 @@
/** variables that hold value property values */
public static final String testSrc;
public static final String testClasses;
+ public static final String testClassPath;
/** name of default security policy for test JVM */
public static final String defaultPolicy;
@@ -57,6 +58,7 @@
static {
testSrc = TestLibrary.getProperty("test.src", ".");
testClasses = TestLibrary.getProperty("test.classes", ".");
+ testClassPath = TestLibrary.getProperty("test.class.path", ".");
String dp = TestLibrary.getProperty("java.security.policy", null);
if (dp == null) {