< prev index next >

src/share/classes/sun/rmi/transport/Target.java

Print this page
rev 12534 : 8174966: Unreferenced references
Reviewed-by: smarks
   1 /*
   2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.rmi.transport;
  26 
  27 import java.rmi.Remote;
  28 import java.rmi.NoSuchObjectException;
  29 import java.rmi.dgc.VMID;
  30 import java.rmi.server.ObjID;
  31 import java.rmi.server.Unreferenced;
  32 import java.security.AccessControlContext;
  33 import java.security.AccessController;

  34 import java.util.*;
  35 import sun.rmi.runtime.Log;
  36 import sun.rmi.runtime.NewThreadAction;
  37 import sun.rmi.server.Dispatcher;
  38 
  39 /**
  40  * A target contains information pertaining to a remote object that
  41  * resides in this address space.  Targets are located via the
  42  * ObjectTable.
  43  */
  44 public final class Target {
  45     /** object id for target */
  46     private final ObjID id;
  47     /** flag indicating whether target is subject to collection */
  48     private final boolean permanent;
  49     /** weak reference to remote object implementation */
  50     private final WeakRef weakImpl;
  51     /** dispatcher for remote object */
  52     private volatile Dispatcher disp;
  53     /** stub for remote object */


 305      */
 306     synchronized private void refSetRemove(VMID vmid) {
 307         // remove notification request
 308         DGCImpl.getDGCImpl().unregisterTarget(vmid, this);
 309 
 310         if (refSet.removeElement(vmid) && refSet.isEmpty()) {
 311             // reference set is empty, so server can be garbage collected.
 312             // remove object from table.
 313             if (DGCImpl.dgcLog.isLoggable(Log.VERBOSE)) {
 314                 DGCImpl.dgcLog.log(Log.VERBOSE,
 315                     "reference set is empty: target = " + this);
 316             }
 317 
 318             /*
 319              * If the remote object implements the Unreferenced interface,
 320              * invoke its unreferenced callback in a separate thread.
 321              */
 322             Remote obj = getImpl();
 323             if (obj instanceof Unreferenced) {
 324                 final Unreferenced unrefObj = (Unreferenced) obj;
 325                 final Thread t =
 326                     java.security.AccessController.doPrivileged(
 327                         new NewThreadAction(new Runnable() {
 328                             public void run() {
 329                                 unrefObj.unreferenced();
 330                             }
 331                         }, "Unreferenced-" + nextThreadNum++, false, true));
 332                 // REMIND: access to nextThreadNum not synchronized; you care?
 333                 /*
 334                  * We must manually set the context class loader appropriately
 335                  * for threads that may invoke user code (see bugid 4171278).
 336                  */
 337                 java.security.AccessController.doPrivileged(
 338                     new java.security.PrivilegedAction<Void>() {
 339                         public Void run() {
 340                         t.setContextClassLoader(ccl);
 341                         return null;
 342                     }
 343                 });
 344 
 345                 t.start();
 346             }
 347 
 348             unpinImpl();
 349         }
 350     }
 351 
 352     /**
 353      * Mark this target as not accepting new calls if any of the
 354      * following conditions exist: a) the force parameter is true,
 355      * b) the target's call count is zero, or c) the object is already
 356      * not accepting calls. Returns true if target is marked as not
 357      * accepting new calls; returns false otherwise.
 358      */
 359     synchronized boolean unexport(boolean force) {
 360 
 361         if ((force == true) || (callCount == 0) || (disp == null)) {
 362             disp = null;
 363             /*
 364              * Fix for 4331349: unpin object so that it may be gc'd.
 365              * Also, unregister all vmids referencing this target


   1 /*
   2  * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package sun.rmi.transport;
  26 
  27 import java.rmi.Remote;
  28 import java.rmi.NoSuchObjectException;
  29 import java.rmi.dgc.VMID;
  30 import java.rmi.server.ObjID;
  31 import java.rmi.server.Unreferenced;
  32 import java.security.AccessControlContext;
  33 import java.security.AccessController;
  34 import java.security.PrivilegedAction;
  35 import java.util.*;
  36 import sun.rmi.runtime.Log;
  37 import sun.rmi.runtime.NewThreadAction;
  38 import sun.rmi.server.Dispatcher;
  39 
  40 /**
  41  * A target contains information pertaining to a remote object that
  42  * resides in this address space.  Targets are located via the
  43  * ObjectTable.
  44  */
  45 public final class Target {
  46     /** object id for target */
  47     private final ObjID id;
  48     /** flag indicating whether target is subject to collection */
  49     private final boolean permanent;
  50     /** weak reference to remote object implementation */
  51     private final WeakRef weakImpl;
  52     /** dispatcher for remote object */
  53     private volatile Dispatcher disp;
  54     /** stub for remote object */


 306      */
 307     synchronized private void refSetRemove(VMID vmid) {
 308         // remove notification request
 309         DGCImpl.getDGCImpl().unregisterTarget(vmid, this);
 310 
 311         if (refSet.removeElement(vmid) && refSet.isEmpty()) {
 312             // reference set is empty, so server can be garbage collected.
 313             // remove object from table.
 314             if (DGCImpl.dgcLog.isLoggable(Log.VERBOSE)) {
 315                 DGCImpl.dgcLog.log(Log.VERBOSE,
 316                     "reference set is empty: target = " + this);
 317             }
 318 
 319             /*
 320              * If the remote object implements the Unreferenced interface,
 321              * invoke its unreferenced callback in a separate thread.
 322              */
 323             Remote obj = getImpl();
 324             if (obj instanceof Unreferenced) {
 325                 final Unreferenced unrefObj = (Unreferenced) obj;
 326                 AccessController.doPrivileged(
 327                     new NewThreadAction(() -> {
 328                         Thread.currentThread().setContextClassLoader(ccl);
 329                         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 330                             unrefObj.unreferenced();











 331                             return null;
 332                         }, acc);
 333                     }, "Unreferenced-" + nextThreadNum++, false, true)).start();
 334                     // REMIND: access to nextThreadNum not synchronized; you care?

 335             }
 336 
 337             unpinImpl();
 338         }
 339     }
 340 
 341     /**
 342      * Mark this target as not accepting new calls if any of the
 343      * following conditions exist: a) the force parameter is true,
 344      * b) the target's call count is zero, or c) the object is already
 345      * not accepting calls. Returns true if target is marked as not
 346      * accepting new calls; returns false otherwise.
 347      */
 348     synchronized boolean unexport(boolean force) {
 349 
 350         if ((force == true) || (callCount == 0) || (disp == null)) {
 351             disp = null;
 352             /*
 353              * Fix for 4331349: unpin object so that it may be gc'd.
 354              * Also, unregister all vmids referencing this target


< prev index next >