< prev index next >

src/java.desktop/share/classes/sun/java2d/marlin/RendererStats.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 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 
  26 package sun.java2d.marlin;
  27 
  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.util.Timer;
  31 import java.util.TimerTask;
  32 import java.util.concurrent.ConcurrentLinkedQueue;
  33 import jdk.internal.ref.CleanerFactory;
  34 import sun.java2d.marlin.ArrayCacheConst.CacheStats;
  35 import static sun.java2d.marlin.MarlinUtils.logInfo;
  36 import sun.java2d.marlin.stats.Histogram;
  37 import sun.java2d.marlin.stats.Monitor;
  38 import sun.java2d.marlin.stats.StatLong;
  39 import sun.awt.util.ThreadGroupUtils;
  40 
  41 /**
  42  * This class gathers global rendering statistics for debugging purposes only
  43  */
  44 public final class RendererStats implements MarlinConst {
  45 
  46     static RendererStats createInstance(final Object parent, final String name)
  47     {
  48         final RendererStats stats = new RendererStats(name);
  49 
  50         // Keep a strong reference to dump it later:
  51         RendererStatsHolder.getInstance().add(parent, stats);
  52 
  53         return stats;
  54     }
  55 
  56     public static void dumpStats() {
  57         RendererStatsHolder.dumpStats();
  58     }
  59 


 342                 SINGLETON = new RendererStatsHolder();
 343             }
 344             return SINGLETON;
 345         }
 346 
 347         static void dumpStats() {
 348             if (SINGLETON != null) {
 349                 SINGLETON.dump();
 350             }
 351         }
 352 
 353         /* RendererStats collection as hard references
 354            (only used for debugging purposes) */
 355         private final ConcurrentLinkedQueue<RendererStats> allStats
 356             = new ConcurrentLinkedQueue<RendererStats>();
 357 
 358         private RendererStatsHolder() {
 359             AccessController.doPrivileged(
 360                 (PrivilegedAction<Void>) () -> {
 361                     final Thread hook = new Thread(
 362                         ThreadGroupUtils.getRootThreadGroup(),
 363                         new Runnable() {
 364                             @Override
 365                             public void run() {
 366                                 dump();
 367                             }
 368                         },
 369                         "MarlinStatsHook"
 370                     );
 371                     hook.setContextClassLoader(null);
 372                     Runtime.getRuntime().addShutdownHook(hook);
 373 
 374                     if (USE_DUMP_THREAD) {
 375                         final Timer statTimer = new Timer("RendererStats");
 376                         statTimer.scheduleAtFixedRate(new TimerTask() {
 377                             @Override
 378                             public void run() {
 379                                 dump();
 380                             }
 381                         }, DUMP_INTERVAL, DUMP_INTERVAL);
 382                     }


   1 /*
   2  * Copyright (c) 2015, 2018, 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 
  26 package sun.java2d.marlin;
  27 
  28 import java.security.AccessController;
  29 import java.security.PrivilegedAction;
  30 import java.util.Timer;
  31 import java.util.TimerTask;
  32 import java.util.concurrent.ConcurrentLinkedQueue;
  33 import jdk.internal.ref.CleanerFactory;
  34 import sun.java2d.marlin.ArrayCacheConst.CacheStats;
  35 import static sun.java2d.marlin.MarlinUtils.logInfo;
  36 import sun.java2d.marlin.stats.Histogram;
  37 import sun.java2d.marlin.stats.Monitor;
  38 import sun.java2d.marlin.stats.StatLong;

  39 
  40 /**
  41  * This class gathers global rendering statistics for debugging purposes only
  42  */
  43 public final class RendererStats implements MarlinConst {
  44 
  45     static RendererStats createInstance(final Object parent, final String name)
  46     {
  47         final RendererStats stats = new RendererStats(name);
  48 
  49         // Keep a strong reference to dump it later:
  50         RendererStatsHolder.getInstance().add(parent, stats);
  51 
  52         return stats;
  53     }
  54 
  55     public static void dumpStats() {
  56         RendererStatsHolder.dumpStats();
  57     }
  58 


 341                 SINGLETON = new RendererStatsHolder();
 342             }
 343             return SINGLETON;
 344         }
 345 
 346         static void dumpStats() {
 347             if (SINGLETON != null) {
 348                 SINGLETON.dump();
 349             }
 350         }
 351 
 352         /* RendererStats collection as hard references
 353            (only used for debugging purposes) */
 354         private final ConcurrentLinkedQueue<RendererStats> allStats
 355             = new ConcurrentLinkedQueue<RendererStats>();
 356 
 357         private RendererStatsHolder() {
 358             AccessController.doPrivileged(
 359                 (PrivilegedAction<Void>) () -> {
 360                     final Thread hook = new Thread(
 361                         MarlinUtils.getRootThreadGroup(),
 362                         new Runnable() {
 363                             @Override
 364                             public void run() {
 365                                 dump();
 366                             }
 367                         },
 368                         "MarlinStatsHook"
 369                     );
 370                     hook.setContextClassLoader(null);
 371                     Runtime.getRuntime().addShutdownHook(hook);
 372 
 373                     if (USE_DUMP_THREAD) {
 374                         final Timer statTimer = new Timer("RendererStats");
 375                         statTimer.scheduleAtFixedRate(new TimerTask() {
 376                             @Override
 377                             public void run() {
 378                                 dump();
 379                             }
 380                         }, DUMP_INTERVAL, DUMP_INTERVAL);
 381                     }


< prev index next >