/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 4171278
* @summary A remote object's unreferenced() method should be invoked with the
* context class loader set to the same context class loader that would be set
* when remote calls for that object are being executed: the object's class's
* class loader, or the context class loader set when the remote object was
* exported, if it is a child of the remote object's class loader.
* @author Peter Jones
*
* @bug 4214123
* @summary Unreferenced.unreferenced(...) threads should run in the nonSystem group.
* To complete the fix for, 4182104, RMI unreferenced threads should also
* run in the nonSystem so that they do not need permissions to modify the
* system thread group.
*
* @author Laird Dornin
*
* @library ../../../testlibrary
* @build TestLibrary UnreferencedContext_Stub
*/
private boolean unreferencedInvoked = false;
public void run() {
}
public void unreferenced() {
// turn on security to ensure that the action below will not
// require extra permissions
// exercise functionality prohibited by 4214123
synchronized (lock) {
unreferencedInvoked = true;
}
}
/*
* Set the interval that RMI will request for GC latency (before RMI
* gets initialized and this property is read) to an unrealistically
* small value, so that this test shouldn't have to wait too long.
*/
try {
/*
* This little trick is necessary to make sure that the RMI server
* threads for objects created on the default port get created
* before we set our special context class loader, so that they
* don't *accidentally* inherit it when making the unreferenced()
* callback.
*/
/*
* Now create special context class loader before exporting the
* remote object for real, so that it should be set when the
* object's unreferenced() method is called.
*/
"created and set intended context class loader: " +
"waiting for unreferenced() callback...");
/*
* This incantation seems sufficient to work around the
* ramifications of 4164696, so that this test will actually
* prove something useful about 1.2Beta4 or 1.2FCS before
* 4171278 was fixed.
*/
for (int i = 0; i < 10; i++) {
if (obj.unreferencedInvoked) {
break;
}
}
if (obj.unreferencedInvoked) {
"invoked with context class loader: " +
"TEST PASSED: unreferenced() invoked" +
" with intended context class loader");
} else {
throw new RuntimeException(
"TEST FAILED: unreferenced() invoked" +
" with incorrect context class loader");
}
} else {
throw new RuntimeException(
"TEST FAILED: unreferenced() not invoked after " +
}
}
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(
"TEST FAILED: unexpected exception: " + 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 {
} catch (RemoteException e) {
}
}
}
}