< prev index next >

src/share/classes/sun/awt/AWTAutoShutdown.java

Print this page
rev 1571 : 8010297: Missing isLoggable() checks in logging code
Summary: Add isLoggable() checks
Reviewed-by: anthony, mchung, serb
Contributed-by: Laurent Bourges <bourges.laurent@gmail.com>


  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 
  26 package sun.awt;
  27 
  28 import java.awt.AWTEvent;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.util.Collections;
  32 import java.util.HashSet;
  33 import java.util.IdentityHashMap;
  34 import java.util.Map;

  35 import java.util.logging.Logger;
  36 
  37 import sun.misc.ThreadGroupUtils;
  38 
  39 /**
  40  * This class is to let AWT shutdown automatically when a user is done
  41  * with AWT. It tracks AWT state using the following parameters:
  42  * <ul>
  43  * <li><code>peerMap</code> - the map between the existing peer objects
  44  *     and their associated targets
  45  * <li><code>toolkitThreadBusy</code> - whether the toolkit thread
  46  *     is waiting for a new native event to appear in its queue
  47  *     or is dispatching an event
  48  * <li><code>busyThreadSet</code> - a set of all the event dispatch
  49  *     threads that are busy at this moment, i.e. those that are not
  50  *     waiting for a new event to appear in their event queue.
  51  * </ul><p>
  52  * AWT is considered to be in ready-to-shutdown state when
  53  * <code>peerMap</code> is empty and <code>toolkitThreadBusy</code>
  54  * is false and <code>busyThreadSet</code> is empty.


 357     final void unregisterPeer(final Object target, final Object peer) {
 358         synchronized (activationLock) {
 359             synchronized (mainLock) {
 360                 if (peerMap.get(target) == peer) {
 361                     peerMap.remove(target);
 362                     notifyPeerMapUpdated();
 363                 }
 364             }
 365         }
 366     }
 367 
 368     final Object getPeer(final Object target) {
 369         synchronized (activationLock) {
 370             synchronized (mainLock) {
 371                 return peerMap.get(target);
 372             }
 373         }
 374     }
 375 
 376     final void dumpPeers(final Logger aLog) {

 377         synchronized (activationLock) {
 378             synchronized (mainLock) {
 379                 aLog.fine("Mapped peers:");
 380                 for (Object key : peerMap.keySet()) {
 381                     aLog.fine(key + "->" + peerMap.get(key));

 382                 }
 383             }
 384         }
 385     }
 386 
 387 } // class AWTAutoShutdown


  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 
  26 package sun.awt;
  27 
  28 import java.awt.AWTEvent;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.util.Collections;
  32 import java.util.HashSet;
  33 import java.util.IdentityHashMap;
  34 import java.util.Map;
  35 import java.util.logging.Level;
  36 import java.util.logging.Logger;
  37 
  38 import sun.misc.ThreadGroupUtils;
  39 
  40 /**
  41  * This class is to let AWT shutdown automatically when a user is done
  42  * with AWT. It tracks AWT state using the following parameters:
  43  * <ul>
  44  * <li><code>peerMap</code> - the map between the existing peer objects
  45  *     and their associated targets
  46  * <li><code>toolkitThreadBusy</code> - whether the toolkit thread
  47  *     is waiting for a new native event to appear in its queue
  48  *     or is dispatching an event
  49  * <li><code>busyThreadSet</code> - a set of all the event dispatch
  50  *     threads that are busy at this moment, i.e. those that are not
  51  *     waiting for a new event to appear in their event queue.
  52  * </ul><p>
  53  * AWT is considered to be in ready-to-shutdown state when
  54  * <code>peerMap</code> is empty and <code>toolkitThreadBusy</code>
  55  * is false and <code>busyThreadSet</code> is empty.


 358     final void unregisterPeer(final Object target, final Object peer) {
 359         synchronized (activationLock) {
 360             synchronized (mainLock) {
 361                 if (peerMap.get(target) == peer) {
 362                     peerMap.remove(target);
 363                     notifyPeerMapUpdated();
 364                 }
 365             }
 366         }
 367     }
 368 
 369     final Object getPeer(final Object target) {
 370         synchronized (activationLock) {
 371             synchronized (mainLock) {
 372                 return peerMap.get(target);
 373             }
 374         }
 375     }
 376 
 377     final void dumpPeers(final Logger aLog) {
 378         if (aLog.isLoggable(Level.FINE)) {
 379             synchronized (activationLock) {
 380                 synchronized (mainLock) {
 381                     aLog.fine("Mapped peers:");
 382                     for (Object key : peerMap.keySet()) {
 383                         aLog.fine(key + "->" + peerMap.get(key));
 384                     }
 385                 }
 386             }
 387         }
 388     }
 389 
 390 } // class AWTAutoShutdown
< prev index next >