24 /* @test
25 * @bug 4171278
26 * @summary A remote object's unreferenced() method should be invoked with the
27 * context class loader set to the same context class loader that would be set
28 * when remote calls for that object are being executed: the object's class's
29 * class loader, or the context class loader set when the remote object was
30 * exported, if it is a child of the remote object's class loader.
31 * @author Peter Jones
32 *
33 * @bug 4214123
34 * @summary Unreferenced.unreferenced(...) threads should run in the nonSystem group.
35 * To complete the fix for, 4182104, RMI unreferenced threads should also
36 * run in the nonSystem so that they do not need permissions to modify the
37 * system thread group.
38 *
39 * @author Laird Dornin
40 *
41 * @library ../../../testlibrary
42 * @build UnreferencedContext
43 * @build UnreferencedContext_Stub
44 * @run main/othervm/timeout=120 UnreferencedContext
45 */
46
47 import java.net.*;
48 import java.rmi.*;
49 import java.rmi.registry.*;
50 import java.rmi.server.*;
51
52 public class UnreferencedContext implements Remote, Unreferenced, Runnable {
53
54 private final static String BINDING = "UnreferencedContext";
55 private final static long GC_INTERVAL = 6000;
56 private final static long TIMEOUT = 60000;
57
58 private Object lock = new Object();
59 private boolean unreferencedInvoked = false;
60 private ClassLoader unreferencedContext;
61
62 public void run() {
63 System.err.println("unreferenced method created thread succesfully");
102 * don't *accidentally* inherit it when making the unreferenced()
103 * callback.
104 */
105 UnicastRemoteObject.exportObject(obj);
106 UnicastRemoteObject.unexportObject(obj, true);
107
108 /*
109 * Now create special context class loader before exporting the
110 * remote object for real, so that it should be set when the
111 * object's unreferenced() method is called.
112 */
113 ClassLoader intendedContext = new URLClassLoader(new URL[0]);
114 Thread.currentThread().setContextClassLoader(intendedContext);
115 System.err.println(
116 "created and set intended context class loader: " +
117 intendedContext);
118
119 UnicastRemoteObject.exportObject(obj);
120 System.err.println("exported remote object");
121
122 LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);
123 System.err.println("created registry");
124
125 Registry registry = LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT);
126 registry.bind(BINDING, obj);
127 System.err.println("bound remote object in registry");
128
129 synchronized (obj.lock) {
130 registry.unbind(BINDING);
131 System.err.println("unbound remote object from registry; " +
132 "waiting for unreferenced() callback...");
133 /*
134 * This incantation seems sufficient to work around the
135 * ramifications of 4164696, so that this test will actually
136 * prove something useful about 1.2Beta4 or 1.2FCS before
137 * 4171278 was fixed.
138 */
139 for (int i = 0; i < 10; i++) {
140 System.gc();
141 obj.lock.wait(TIMEOUT / 10);
142 if (obj.unreferencedInvoked) {
143 break;
144 }
145 }
|
24 /* @test
25 * @bug 4171278
26 * @summary A remote object's unreferenced() method should be invoked with the
27 * context class loader set to the same context class loader that would be set
28 * when remote calls for that object are being executed: the object's class's
29 * class loader, or the context class loader set when the remote object was
30 * exported, if it is a child of the remote object's class loader.
31 * @author Peter Jones
32 *
33 * @bug 4214123
34 * @summary Unreferenced.unreferenced(...) threads should run in the nonSystem group.
35 * To complete the fix for, 4182104, RMI unreferenced threads should also
36 * run in the nonSystem so that they do not need permissions to modify the
37 * system thread group.
38 *
39 * @author Laird Dornin
40 *
41 * @library ../../../testlibrary
42 * @build UnreferencedContext
43 * @build UnreferencedContext_Stub
44 * @build TestLibrary
45 * @run main/othervm/timeout=120 UnreferencedContext
46 */
47
48 import java.net.*;
49 import java.rmi.*;
50 import java.rmi.registry.*;
51 import java.rmi.server.*;
52
53 public class UnreferencedContext implements Remote, Unreferenced, Runnable {
54
55 private final static String BINDING = "UnreferencedContext";
56 private final static long GC_INTERVAL = 6000;
57 private final static long TIMEOUT = 60000;
58
59 private Object lock = new Object();
60 private boolean unreferencedInvoked = false;
61 private ClassLoader unreferencedContext;
62
63 public void run() {
64 System.err.println("unreferenced method created thread succesfully");
103 * don't *accidentally* inherit it when making the unreferenced()
104 * callback.
105 */
106 UnicastRemoteObject.exportObject(obj);
107 UnicastRemoteObject.unexportObject(obj, true);
108
109 /*
110 * Now create special context class loader before exporting the
111 * remote object for real, so that it should be set when the
112 * object's unreferenced() method is called.
113 */
114 ClassLoader intendedContext = new URLClassLoader(new URL[0]);
115 Thread.currentThread().setContextClassLoader(intendedContext);
116 System.err.println(
117 "created and set intended context class loader: " +
118 intendedContext);
119
120 UnicastRemoteObject.exportObject(obj);
121 System.err.println("exported remote object");
122
123 Registry registry1 = TestLibrary.createRegistryOnUnusedPort();
124 int port = TestLibrary.getRegistryPort(registry1);
125 System.err.println("created registry");
126
127 Registry registry = LocateRegistry.getRegistry("", port);
128 registry.bind(BINDING, obj);
129 System.err.println("bound remote object in registry");
130
131 synchronized (obj.lock) {
132 registry.unbind(BINDING);
133 System.err.println("unbound remote object from registry; " +
134 "waiting for unreferenced() callback...");
135 /*
136 * This incantation seems sufficient to work around the
137 * ramifications of 4164696, so that this test will actually
138 * prove something useful about 1.2Beta4 or 1.2FCS before
139 * 4171278 was fixed.
140 */
141 for (int i = 0; i < 10; i++) {
142 System.gc();
143 obj.lock.wait(TIMEOUT / 10);
144 if (obj.unreferencedInvoked) {
145 break;
146 }
147 }
|