< prev index next >

openjfx9/modules/javafx.graphics/src/main/java/com/sun/marlin/RendererStats.java

Print this page




   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 


  98         = new StatLong("renderer.activeEdges.adds");
  99     final StatLong stat_rdr_activeEdges_adds_high
 100         = new StatLong("renderer.activeEdges.adds_high");
 101     final StatLong stat_rdr_crossings_updates
 102         = new StatLong("renderer.crossings.updates");
 103     final StatLong stat_rdr_crossings_sorts
 104         = new StatLong("renderer.crossings.sorts");
 105     final StatLong stat_rdr_crossings_bsearch
 106         = new StatLong("renderer.crossings.bsearch");
 107     final StatLong stat_rdr_crossings_msorts
 108         = new StatLong("renderer.crossings.msorts");
 109     // growable arrays
 110     final StatLong stat_array_dasher_dasher
 111         = new StatLong("array.dasher.dasher.d_float");
 112     final StatLong stat_array_dasher_firstSegmentsBuffer
 113         = new StatLong("array.dasher.firstSegmentsBuffer.d_float");
 114     final StatLong stat_array_stroker_polystack_curves
 115         = new StatLong("array.stroker.polystack.curves.d_float");
 116     final StatLong stat_array_stroker_polystack_curveTypes
 117         = new StatLong("array.stroker.polystack.curveTypes.d_byte");
 118     final StatLong stat_array_marlincache_rowAAChunk
 119         = new StatLong("array.marlincache.rowAAChunk.resize");
 120     final StatLong stat_array_marlincache_touchedTile
 121         = new StatLong("array.marlincache.touchedTile.int");
 122     final StatLong stat_array_renderer_alphaline
 123         = new StatLong("array.renderer.alphaline.int");
 124     final StatLong stat_array_renderer_crossings
 125         = new StatLong("array.renderer.crossings.int");
 126     final StatLong stat_array_renderer_aux_crossings
 127         = new StatLong("array.renderer.aux_crossings.int");
 128     final StatLong stat_array_renderer_edgeBuckets
 129         = new StatLong("array.renderer.edgeBuckets.int");
 130     final StatLong stat_array_renderer_edgeBucketCounts
 131         = new StatLong("array.renderer.edgeBucketCounts.int");
 132     final StatLong stat_array_renderer_edgePtrs
 133         = new StatLong("array.renderer.edgePtrs.int");
 134     final StatLong stat_array_renderer_aux_edgePtrs
 135         = new StatLong("array.renderer.aux_edgePtrs.int");
 136     // histograms
 137     final Histogram hist_rdr_edges_count
 138         = new Histogram("renderer.edges.count");
 139     final Histogram hist_rdr_poly_stack_curves
 140         = new Histogram("renderer.polystack.curves");
 141     final Histogram hist_rdr_crossings
 142         = new Histogram("renderer.crossings");
 143     final Histogram hist_rdr_crossings_ratio
 144         = new Histogram("renderer.crossings.ratio");
 145     final Histogram hist_rdr_crossings_adds
 146         = new Histogram("renderer.crossings.adds");
 147     final Histogram hist_rdr_crossings_msorts
 148         = new Histogram("renderer.crossings.msorts");
 149     final Histogram hist_rdr_crossings_msorts_adds
 150         = new Histogram("renderer.crossings.msorts.adds");
 151     final Histogram hist_tile_generator_alpha
 152         = new Histogram("tile_generator.alpha");
 153     final Histogram hist_tile_generator_encoding
 154         = new Histogram("tile_generator.encoding");
 155     final Histogram hist_tile_generator_encoding_dist
 156         = new Histogram("tile_generator.encoding.dist");
 157     final Histogram hist_tile_generator_encoding_ratio
 158         = new Histogram("tile_generator.encoding.ratio");
 159     final Histogram hist_tile_generator_encoding_runLen
 160         = new Histogram("tile_generator.encoding.runLen");
 161     // all stats
 162     final StatLong[] statistics = new StatLong[]{
 163         stat_cache_rowAA,
 164         stat_cache_rowAAChunk,
 165         stat_cache_tiles,
 166         stat_rdr_poly_stack_types,
 167         stat_rdr_poly_stack_curves,
 168         stat_rdr_addLine,
 169         stat_rdr_addLine_skip,
 170         stat_rdr_curveBreak,
 171         stat_rdr_curveBreak_dec,
 172         stat_rdr_curveBreak_inc,
 173         stat_rdr_quadBreak,
 174         stat_rdr_quadBreak_dec,
 175         stat_rdr_edges,
 176         stat_rdr_edges_count,
 177         stat_rdr_edges_resizes,
 178         stat_rdr_activeEdges,
 179         stat_rdr_activeEdges_updates,
 180         stat_rdr_activeEdges_adds,
 181         stat_rdr_activeEdges_adds_high,
 182         stat_rdr_crossings_updates,
 183         stat_rdr_crossings_sorts,
 184         stat_rdr_crossings_bsearch,
 185         stat_rdr_crossings_msorts,
 186         hist_rdr_edges_count,
 187         hist_rdr_poly_stack_curves,
 188         hist_rdr_crossings,
 189         hist_rdr_crossings_ratio,
 190         hist_rdr_crossings_adds,
 191         hist_rdr_crossings_msorts,
 192         hist_rdr_crossings_msorts_adds,
 193         hist_tile_generator_alpha,
 194         hist_tile_generator_encoding,
 195         hist_tile_generator_encoding_dist,
 196         hist_tile_generator_encoding_ratio,
 197         hist_tile_generator_encoding_runLen,
 198         stat_array_dasher_dasher,
 199         stat_array_dasher_firstSegmentsBuffer,
 200         stat_array_stroker_polystack_curves,
 201         stat_array_stroker_polystack_curveTypes,
 202         stat_array_marlincache_rowAAChunk,
 203         stat_array_marlincache_touchedTile,
 204         stat_array_renderer_alphaline,
 205         stat_array_renderer_crossings,
 206         stat_array_renderer_aux_crossings,
 207         stat_array_renderer_edgeBuckets,
 208         stat_array_renderer_edgeBucketCounts,
 209         stat_array_renderer_edgePtrs,
 210         stat_array_renderer_aux_edgePtrs
 211     };
 212     // monitors
 213     final Monitor mon_pre_getAATileGenerator
 214         = new Monitor("MarlinRenderingEngine.getAATileGenerator()");
 215     final Monitor mon_rdr_addLine
 216         = new Monitor("Renderer.addLine()");
 217     final Monitor mon_rdr_endRendering
 218         = new Monitor("Renderer.endRendering()");
 219     final Monitor mon_rdr_endRendering_Y
 220         = new Monitor("Renderer._endRendering(Y)");
 221     final Monitor mon_rdr_copyAARow
 222         = new Monitor("Renderer.copyAARow()");
 223     final Monitor mon_pipe_renderTiles


 318                 SINGLETON = new RendererStatsHolder();
 319             }
 320             return SINGLETON;
 321         }
 322 
 323         static void dumpStats() {
 324             if (SINGLETON != null) {
 325                 SINGLETON.dump();
 326             }
 327         }
 328 
 329         /* RendererStats collection as hard references
 330            (only used for debugging purposes) */
 331         private final ConcurrentLinkedQueue<RendererStats> allStats
 332             = new ConcurrentLinkedQueue<RendererStats>();
 333 
 334         private RendererStatsHolder() {
 335             AccessController.doPrivileged(
 336                 (PrivilegedAction<Void>) () -> {
 337                     final Thread hook = new Thread(
 338                         ThreadGroupUtils.getRootThreadGroup(),
 339                         new Runnable() {
 340                             @Override
 341                             public void run() {
 342                                 dump();
 343                             }
 344                         },
 345                         "MarlinStatsHook"
 346                     );
 347                     hook.setContextClassLoader(null);
 348                     Runtime.getRuntime().addShutdownHook(hook);
 349 
 350                     if (USE_DUMP_THREAD) {
 351                         final Timer statTimer = new Timer("RendererStats");
 352                         statTimer.scheduleAtFixedRate(new TimerTask() {
 353                             @Override
 354                             public void run() {
 355                                 dump();
 356                             }
 357                         }, DUMP_INTERVAL, DUMP_INTERVAL);
 358                     }
 359                     return null;
 360                 }
 361             );
 362         }
 363 
 364         void add(final Object parent, final RendererStats stats) {
 365             allStats.add(stats);
 366 
 367             // Register a cleaning function to ensure removing dead entries:
 368             CleanerFactory.cleaner().register(parent, () -> remove(stats));
 369         }
 370 
 371         void remove(final RendererStats stats) {
 372             stats.dump(); // dump anyway
 373             allStats.remove(stats);
 374         }
 375 
 376         void dump() {
 377             for (RendererStats stats : allStats) {
 378                 stats.dump();
 379             }
 380         }
 381     }
 382 }


   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 com.sun.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 com.sun.marlin.ArrayCacheConst.CacheStats;
  34 import static com.sun.marlin.MarlinUtils.logInfo;
  35 import com.sun.marlin.stats.Histogram;
  36 import com.sun.marlin.stats.Monitor;
  37 import com.sun.marlin.stats.StatLong;


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


  96         = new StatLong("renderer.activeEdges.adds");
  97     final StatLong stat_rdr_activeEdges_adds_high
  98         = new StatLong("renderer.activeEdges.adds_high");
  99     final StatLong stat_rdr_crossings_updates
 100         = new StatLong("renderer.crossings.updates");
 101     final StatLong stat_rdr_crossings_sorts
 102         = new StatLong("renderer.crossings.sorts");
 103     final StatLong stat_rdr_crossings_bsearch
 104         = new StatLong("renderer.crossings.bsearch");
 105     final StatLong stat_rdr_crossings_msorts
 106         = new StatLong("renderer.crossings.msorts");
 107     // growable arrays
 108     final StatLong stat_array_dasher_dasher
 109         = new StatLong("array.dasher.dasher.d_float");
 110     final StatLong stat_array_dasher_firstSegmentsBuffer
 111         = new StatLong("array.dasher.firstSegmentsBuffer.d_float");
 112     final StatLong stat_array_stroker_polystack_curves
 113         = new StatLong("array.stroker.polystack.curves.d_float");
 114     final StatLong stat_array_stroker_polystack_curveTypes
 115         = new StatLong("array.stroker.polystack.curveTypes.d_byte");




 116     final StatLong stat_array_renderer_alphaline
 117         = new StatLong("array.renderer.alphaline.int");
 118     final StatLong stat_array_renderer_crossings
 119         = new StatLong("array.renderer.crossings.int");
 120     final StatLong stat_array_renderer_aux_crossings
 121         = new StatLong("array.renderer.aux_crossings.int");
 122     final StatLong stat_array_renderer_edgeBuckets
 123         = new StatLong("array.renderer.edgeBuckets.int");
 124     final StatLong stat_array_renderer_edgeBucketCounts
 125         = new StatLong("array.renderer.edgeBucketCounts.int");
 126     final StatLong stat_array_renderer_edgePtrs
 127         = new StatLong("array.renderer.edgePtrs.int");
 128     final StatLong stat_array_renderer_aux_edgePtrs
 129         = new StatLong("array.renderer.aux_edgePtrs.int");
 130     // histograms
 131     final Histogram hist_rdr_edges_count
 132         = new Histogram("renderer.edges.count");
 133     final Histogram hist_rdr_poly_stack_curves
 134         = new Histogram("renderer.polystack.curves");
 135     final Histogram hist_rdr_crossings
 136         = new Histogram("renderer.crossings");
 137     final Histogram hist_rdr_crossings_ratio
 138         = new Histogram("renderer.crossings.ratio");
 139     final Histogram hist_rdr_crossings_adds
 140         = new Histogram("renderer.crossings.adds");
 141     final Histogram hist_rdr_crossings_msorts
 142         = new Histogram("renderer.crossings.msorts");
 143     final Histogram hist_rdr_crossings_msorts_adds
 144         = new Histogram("renderer.crossings.msorts.adds");


 145     final Histogram hist_tile_generator_encoding
 146         = new Histogram("tile_generator.encoding");
 147     final Histogram hist_tile_generator_encoding_dist
 148         = new Histogram("tile_generator.encoding.dist");




 149     // all stats
 150     final StatLong[] statistics = new StatLong[]{
 151         stat_cache_rowAA,
 152         stat_cache_rowAAChunk,
 153         stat_cache_tiles,
 154         stat_rdr_poly_stack_types,
 155         stat_rdr_poly_stack_curves,
 156         stat_rdr_addLine,
 157         stat_rdr_addLine_skip,
 158         stat_rdr_curveBreak,
 159         stat_rdr_curveBreak_dec,
 160         stat_rdr_curveBreak_inc,
 161         stat_rdr_quadBreak,
 162         stat_rdr_quadBreak_dec,
 163         stat_rdr_edges,
 164         stat_rdr_edges_count,
 165         stat_rdr_edges_resizes,
 166         stat_rdr_activeEdges,
 167         stat_rdr_activeEdges_updates,
 168         stat_rdr_activeEdges_adds,
 169         stat_rdr_activeEdges_adds_high,
 170         stat_rdr_crossings_updates,
 171         stat_rdr_crossings_sorts,
 172         stat_rdr_crossings_bsearch,
 173         stat_rdr_crossings_msorts,
 174         hist_rdr_edges_count,
 175         hist_rdr_poly_stack_curves,
 176         hist_rdr_crossings,
 177         hist_rdr_crossings_ratio,
 178         hist_rdr_crossings_adds,
 179         hist_rdr_crossings_msorts,
 180         hist_rdr_crossings_msorts_adds,

 181         hist_tile_generator_encoding,
 182         hist_tile_generator_encoding_dist,


 183         stat_array_dasher_dasher,
 184         stat_array_dasher_firstSegmentsBuffer,
 185         stat_array_stroker_polystack_curves,
 186         stat_array_stroker_polystack_curveTypes,


 187         stat_array_renderer_alphaline,
 188         stat_array_renderer_crossings,
 189         stat_array_renderer_aux_crossings,
 190         stat_array_renderer_edgeBuckets,
 191         stat_array_renderer_edgeBucketCounts,
 192         stat_array_renderer_edgePtrs,
 193         stat_array_renderer_aux_edgePtrs
 194     };
 195     // monitors
 196     final Monitor mon_pre_getAATileGenerator
 197         = new Monitor("MarlinRenderingEngine.getAATileGenerator()");
 198     final Monitor mon_rdr_addLine
 199         = new Monitor("Renderer.addLine()");
 200     final Monitor mon_rdr_endRendering
 201         = new Monitor("Renderer.endRendering()");
 202     final Monitor mon_rdr_endRendering_Y
 203         = new Monitor("Renderer._endRendering(Y)");
 204     final Monitor mon_rdr_copyAARow
 205         = new Monitor("Renderer.copyAARow()");
 206     final Monitor mon_pipe_renderTiles


 301                 SINGLETON = new RendererStatsHolder();
 302             }
 303             return SINGLETON;
 304         }
 305 
 306         static void dumpStats() {
 307             if (SINGLETON != null) {
 308                 SINGLETON.dump();
 309             }
 310         }
 311 
 312         /* RendererStats collection as hard references
 313            (only used for debugging purposes) */
 314         private final ConcurrentLinkedQueue<RendererStats> allStats
 315             = new ConcurrentLinkedQueue<RendererStats>();
 316 
 317         private RendererStatsHolder() {
 318             AccessController.doPrivileged(
 319                 (PrivilegedAction<Void>) () -> {
 320                     final Thread hook = new Thread(
 321                         MarlinUtils.getRootThreadGroup(),
 322                         new Runnable() {
 323                             @Override
 324                             public void run() {
 325                                 dump();
 326                             }
 327                         },
 328                         "MarlinStatsHook"
 329                     );
 330                     hook.setContextClassLoader(null);
 331                     Runtime.getRuntime().addShutdownHook(hook);
 332 
 333                     if (USE_DUMP_THREAD) {
 334                         final Timer statTimer = new Timer("RendererStats");
 335                         statTimer.scheduleAtFixedRate(new TimerTask() {
 336                             @Override
 337                             public void run() {
 338                                 dump();
 339                             }
 340                         }, DUMP_INTERVAL, DUMP_INTERVAL);
 341                     }
 342                     return null;
 343                 }
 344             );
 345         }
 346 
 347         void add(final Object parent, final RendererStats stats) {
 348             allStats.add(stats);
 349 
 350             // Register a cleaning function to ensure removing dead entries:
 351             MarlinUtils.getCleaner().register(parent, () -> remove(stats));
 352         }
 353 
 354         void remove(final RendererStats stats) {
 355             stats.dump(); // dump anyway
 356             allStats.remove(stats);
 357         }
 358 
 359         void dump() {
 360             for (RendererStats stats : allStats) {
 361                 stats.dump();
 362             }
 363         }
 364     }
 365 }
< prev index next >