Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/marlin/RendererStats.java
38918 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.marlin;2627import java.security.AccessController;28import java.security.PrivilegedAction;29import java.util.Timer;30import java.util.TimerTask;31import java.util.concurrent.ConcurrentLinkedQueue;32import static sun.java2d.marlin.MarlinUtils.logInfo;33import sun.java2d.marlin.stats.Histogram;34import sun.java2d.marlin.stats.Monitor;35import sun.java2d.marlin.stats.StatLong;36import sun.misc.ThreadGroupUtils;3738/**39* This class gathers global rendering statistics for debugging purposes only40*/41public final class RendererStats implements MarlinConst {4243// singleton44private static volatile RendererStats singleton = null;4546static RendererStats getInstance() {47if (singleton == null) {48singleton = new RendererStats();49}50return singleton;51}5253public static void dumpStats() {54if (singleton != null) {55singleton.dump();56}57}5859/* RendererContext collection as hard references60(only used for debugging purposes) */61final ConcurrentLinkedQueue<RendererContext> allContexts62= new ConcurrentLinkedQueue<RendererContext>();63// stats64final StatLong stat_cache_rowAA65= new StatLong("cache.rowAA");66final StatLong stat_cache_rowAAChunk67= new StatLong("cache.rowAAChunk");68final StatLong stat_cache_tiles69= new StatLong("cache.tiles");70final StatLong stat_rdr_poly_stack_curves71= new StatLong("renderer.poly.stack.curves");72final StatLong stat_rdr_poly_stack_types73= new StatLong("renderer.poly.stack.types");74final StatLong stat_rdr_addLine75= new StatLong("renderer.addLine");76final StatLong stat_rdr_addLine_skip77= new StatLong("renderer.addLine.skip");78final StatLong stat_rdr_curveBreak79= new StatLong("renderer.curveBreakIntoLinesAndAdd");80final StatLong stat_rdr_curveBreak_dec81= new StatLong("renderer.curveBreakIntoLinesAndAdd.dec");82final StatLong stat_rdr_curveBreak_inc83= new StatLong("renderer.curveBreakIntoLinesAndAdd.inc");84final StatLong stat_rdr_quadBreak85= new StatLong("renderer.quadBreakIntoLinesAndAdd");86final StatLong stat_rdr_quadBreak_dec87= new StatLong("renderer.quadBreakIntoLinesAndAdd.dec");88final StatLong stat_rdr_edges89= new StatLong("renderer.edges");90final StatLong stat_rdr_edges_count91= new StatLong("renderer.edges.count");92final StatLong stat_rdr_edges_resizes93= new StatLong("renderer.edges.resize");94final StatLong stat_rdr_activeEdges95= new StatLong("renderer.activeEdges");96final StatLong stat_rdr_activeEdges_updates97= new StatLong("renderer.activeEdges.updates");98final StatLong stat_rdr_activeEdges_adds99= new StatLong("renderer.activeEdges.adds");100final StatLong stat_rdr_activeEdges_adds_high101= new StatLong("renderer.activeEdges.adds_high");102final StatLong stat_rdr_crossings_updates103= new StatLong("renderer.crossings.updates");104final StatLong stat_rdr_crossings_sorts105= new StatLong("renderer.crossings.sorts");106final StatLong stat_rdr_crossings_bsearch107= new StatLong("renderer.crossings.bsearch");108final StatLong stat_rdr_crossings_msorts109= new StatLong("renderer.crossings.msorts");110// growable arrays111final StatLong stat_array_dasher_dasher112= new StatLong("array.dasher.dasher.d_float");113final StatLong stat_array_dasher_firstSegmentsBuffer114= new StatLong("array.dasher.firstSegmentsBuffer.d_float");115final StatLong stat_array_stroker_polystack_curves116= new StatLong("array.stroker.polystack.curves.d_float");117final StatLong stat_array_stroker_polystack_curveTypes118= new StatLong("array.stroker.polystack.curveTypes.d_byte");119final StatLong stat_array_marlincache_rowAAChunk120= new StatLong("array.marlincache.rowAAChunk.d_byte");121final StatLong stat_array_marlincache_touchedTile122= new StatLong("array.marlincache.touchedTile.int");123final StatLong stat_array_renderer_alphaline124= new StatLong("array.renderer.alphaline.int");125final StatLong stat_array_renderer_crossings126= new StatLong("array.renderer.crossings.int");127final StatLong stat_array_renderer_aux_crossings128= new StatLong("array.renderer.aux_crossings.int");129final StatLong stat_array_renderer_edgeBuckets130= new StatLong("array.renderer.edgeBuckets.int");131final StatLong stat_array_renderer_edgeBucketCounts132= new StatLong("array.renderer.edgeBucketCounts.int");133final StatLong stat_array_renderer_edgePtrs134= new StatLong("array.renderer.edgePtrs.int");135final StatLong stat_array_renderer_aux_edgePtrs136= new StatLong("array.renderer.aux_edgePtrs.int");137// histograms138final Histogram hist_rdr_crossings139= new Histogram("renderer.crossings");140final Histogram hist_rdr_crossings_ratio141= new Histogram("renderer.crossings.ratio");142final Histogram hist_rdr_crossings_adds143= new Histogram("renderer.crossings.adds");144final Histogram hist_rdr_crossings_msorts145= new Histogram("renderer.crossings.msorts");146final Histogram hist_rdr_crossings_msorts_adds147= new Histogram("renderer.crossings.msorts.adds");148final Histogram hist_tile_generator_alpha149= new Histogram("tile_generator.alpha");150final Histogram hist_tile_generator_encoding151= new Histogram("tile_generator.encoding");152final Histogram hist_tile_generator_encoding_dist153= new Histogram("tile_generator.encoding.dist");154final Histogram hist_tile_generator_encoding_ratio155= new Histogram("tile_generator.encoding.ratio");156final Histogram hist_tile_generator_encoding_runLen157= new Histogram("tile_generator.encoding.runLen");158// all stats159final StatLong[] statistics = new StatLong[]{160stat_cache_rowAA,161stat_cache_rowAAChunk,162stat_cache_tiles,163stat_rdr_poly_stack_types,164stat_rdr_poly_stack_curves,165stat_rdr_addLine,166stat_rdr_addLine_skip,167stat_rdr_curveBreak,168stat_rdr_curveBreak_dec,169stat_rdr_curveBreak_inc,170stat_rdr_quadBreak,171stat_rdr_quadBreak_dec,172stat_rdr_edges,173stat_rdr_edges_count,174stat_rdr_edges_resizes,175stat_rdr_activeEdges,176stat_rdr_activeEdges_updates,177stat_rdr_activeEdges_adds,178stat_rdr_activeEdges_adds_high,179stat_rdr_crossings_updates,180stat_rdr_crossings_sorts,181stat_rdr_crossings_bsearch,182stat_rdr_crossings_msorts,183hist_rdr_crossings,184hist_rdr_crossings_ratio,185hist_rdr_crossings_adds,186hist_rdr_crossings_msorts,187hist_rdr_crossings_msorts_adds,188hist_tile_generator_alpha,189hist_tile_generator_encoding,190hist_tile_generator_encoding_dist,191hist_tile_generator_encoding_ratio,192hist_tile_generator_encoding_runLen,193stat_array_dasher_dasher,194stat_array_dasher_firstSegmentsBuffer,195stat_array_stroker_polystack_curves,196stat_array_stroker_polystack_curveTypes,197stat_array_marlincache_rowAAChunk,198stat_array_marlincache_touchedTile,199stat_array_renderer_alphaline,200stat_array_renderer_crossings,201stat_array_renderer_aux_crossings,202stat_array_renderer_edgeBuckets,203stat_array_renderer_edgeBucketCounts,204stat_array_renderer_edgePtrs,205stat_array_renderer_aux_edgePtrs206};207// monitors208final Monitor mon_pre_getAATileGenerator209= new Monitor("MarlinRenderingEngine.getAATileGenerator()");210final Monitor mon_npi_currentSegment211= new Monitor("NormalizingPathIterator.currentSegment()");212final Monitor mon_rdr_addLine213= new Monitor("Renderer.addLine()");214final Monitor mon_rdr_endRendering215= new Monitor("Renderer.endRendering()");216final Monitor mon_rdr_endRendering_Y217= new Monitor("Renderer._endRendering(Y)");218final Monitor mon_rdr_copyAARow219= new Monitor("Renderer.copyAARow()");220final Monitor mon_pipe_renderTiles221= new Monitor("AAShapePipe.renderTiles()");222final Monitor mon_ptg_getAlpha223= new Monitor("MarlinTileGenerator.getAlpha()");224final Monitor mon_debug225= new Monitor("DEBUG()");226// all monitors227final Monitor[] monitors = new Monitor[]{228mon_pre_getAATileGenerator,229mon_npi_currentSegment,230mon_rdr_addLine,231mon_rdr_endRendering,232mon_rdr_endRendering_Y,233mon_rdr_copyAARow,234mon_pipe_renderTiles,235mon_ptg_getAlpha,236mon_debug237};238239private RendererStats() {240super();241242AccessController.doPrivileged(243(PrivilegedAction<Void>) () -> {244final Thread hook = new Thread(245ThreadGroupUtils.getRootThreadGroup(),246new Runnable() {247@Override248public void run() {249dump();250}251},252"MarlinStatsHook"253);254hook.setContextClassLoader(null);255Runtime.getRuntime().addShutdownHook(hook);256257if (useDumpThread) {258final Timer statTimer = new Timer("RendererStats");259statTimer.scheduleAtFixedRate(new TimerTask() {260@Override261public void run() {262dump();263}264}, statDump, statDump);265}266return null;267}268);269}270271void dump() {272if (doStats) {273ArrayCache.dumpStats();274}275final RendererContext[] all = allContexts.toArray(276new RendererContext[allContexts.size()]);277for (RendererContext rdrCtx : all) {278logInfo("RendererContext: " + rdrCtx.name);279280if (doMonitors) {281for (Monitor monitor : monitors) {282if (monitor.count != 0) {283logInfo(monitor.toString());284}285}286// As getAATileGenerator percents:287final long total = mon_pre_getAATileGenerator.sum;288if (total != 0L) {289for (Monitor monitor : monitors) {290logInfo(monitor.name + " : "291+ ((100d * monitor.sum) / total) + " %");292}293}294if (doFlushMonitors) {295for (Monitor m : monitors) {296m.reset();297}298}299}300301if (doStats) {302for (StatLong stat : statistics) {303if (stat.count != 0) {304logInfo(stat.toString());305stat.reset();306}307}308// IntArrayCaches stats:309final RendererContext.ArrayCachesHolder holder310= rdrCtx.getArrayCachesHolder();311312logInfo("Array caches for thread: " + rdrCtx.name);313314for (IntArrayCache cache : holder.intArrayCaches) {315cache.dumpStats();316}317318logInfo("Dirty Array caches for thread: " + rdrCtx.name);319320for (IntArrayCache cache : holder.dirtyIntArrayCaches) {321cache.dumpStats();322}323for (FloatArrayCache cache : holder.dirtyFloatArrayCaches) {324cache.dumpStats();325}326for (ByteArrayCache cache : holder.dirtyByteArrayCaches) {327cache.dumpStats();328}329}330}331}332}333334335