Print this page
Added gradle and cmake project

Split Close
Expand all
Collapse all
          --- old/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitive.java
          +++ new/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitive.java
↓ open down ↓ 32 lines elided ↑ open up ↑
  33   33  import java.awt.AlphaComposite;
  34   34  import java.awt.Rectangle;
  35   35  import sun.awt.image.BufImgSurfaceData;
  36   36  import sun.awt.util.ThreadGroupUtils;
  37   37  import sun.java2d.SurfaceData;
  38   38  import sun.java2d.pipe.Region;
  39   39  import java.lang.reflect.Field;
  40   40  import java.util.StringTokenizer;
  41   41  import java.util.Iterator;
  42   42  import java.util.HashMap;
       43 +import java.util.HashSet;
  43   44  import java.util.Map;
  44   45  import java.io.PrintStream;
  45   46  import java.io.OutputStream;
  46   47  import java.io.FileOutputStream;
  47   48  import java.io.FileNotFoundException;
  48   49  import java.security.AccessController;
  49   50  import java.security.PrivilegedAction;
  50   51  
  51   52  import sun.security.action.GetPropertyAction;
  52   53  
↓ open down ↓ 259 lines elided ↑ open up ↑
 312  313                  destType.equals(other.destType));
 313  314      }
 314  315  
 315  316      public abstract GraphicsPrimitive makePrimitive(SurfaceType srctype,
 316  317                                                      CompositeType comptype,
 317  318                                                      SurfaceType dsttype);
 318  319  
 319  320      public abstract GraphicsPrimitive traceWrap();
 320  321  
 321  322      static HashMap<Object, int[]> traceMap;
      323 +    static HashSet<String> traceNotImplSet;
 322  324  
 323  325      public static int traceflags;
 324  326      public static String tracefile;
      327 +    public static String pname;
 325  328      public static PrintStream traceout;
      329 +    public static long treshold = 0;
      330 +    public static boolean verbose = false;
 326  331  
 327  332      public static final int TRACELOG = 1;
 328  333      public static final int TRACETIMESTAMP = 2;
 329  334      public static final int TRACECOUNTS = 4;
      335 +    public static final int TRACEPTIME = 8;
      336 +    public static final int TRACEPNAME = 16;
      337 +    public static final int TRACENOTIMPL = 32;
      338 +
      339 +    static void showTraceUsage() {
      340 +        System.err.println("usage: -Dsun.java2d.trace="+
      341 +                "[log[,timestamp]],[count],[ptime],[name:<substr pattern>],"+
      342 +                "[out:<filename>],[td=<treshold>],[help],[verbose]");
      343 +    }
 330  344  
 331  345      static {
 332  346          GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace");
 333  347          String trace = AccessController.doPrivileged(gpa);
 334  348          if (trace != null) {
 335      -            boolean verbose = false;
 336  349              int traceflags = 0;
 337  350              StringTokenizer st = new StringTokenizer(trace, ",");
 338  351              while (st.hasMoreTokens()) {
 339  352                  String tok = st.nextToken();
 340  353                  if (tok.equalsIgnoreCase("count")) {
 341  354                      traceflags |= GraphicsPrimitive.TRACECOUNTS;
 342  355                  } else if (tok.equalsIgnoreCase("log")) {
 343  356                      traceflags |= GraphicsPrimitive.TRACELOG;
 344  357                  } else if (tok.equalsIgnoreCase("timestamp")) {
 345  358                      traceflags |= GraphicsPrimitive.TRACETIMESTAMP;
      359 +                } else if (tok.equalsIgnoreCase("ptime")) {
      360 +                    traceflags |=GraphicsPrimitive.TRACEPTIME;
      361 +                } else if (tok.equalsIgnoreCase("notimpl")) {
      362 +                    traceflags |=GraphicsPrimitive.TRACENOTIMPL;
      363 +                } else if (tok.regionMatches(true, 0, "name:", 0, 5)) {
      364 +                    traceflags |=GraphicsPrimitive.TRACEPNAME;
      365 +                    pname = tok.substring(6);
 346  366                  } else if (tok.equalsIgnoreCase("verbose")) {
 347  367                      verbose = true;
 348  368                  } else if (tok.regionMatches(true, 0, "out:", 0, 4)) {
 349  369                      tracefile = tok.substring(4);
      370 +                } else if (tok.regionMatches(true, 0, "td=", 0, 3)) {
      371 +                    try {
      372 +                        treshold = Long.parseLong(tok.substring(3));
      373 +                    } catch (NumberFormatException e) {
      374 +                        showTraceUsage();
      375 +                    }
 350  376                  } else {
 351  377                      if (!tok.equalsIgnoreCase("help")) {
 352  378                          System.err.println("unrecognized token: "+tok);
 353  379                      }
 354      -                    System.err.println("usage: -Dsun.java2d.trace="+
 355      -                                       "[log[,timestamp]],[count],"+
 356      -                                       "[out:<filename>],[help],[verbose]");
      380 +                    showTraceUsage();
 357  381                  }
 358  382              }
      383 +
      384 +            GraphicsPrimitiveMgr.setTraceFlags(traceflags);
      385 +
 359  386              if (verbose) {
 360  387                  System.err.print("GraphicsPrimitive logging ");
 361  388                  if ((traceflags & GraphicsPrimitive.TRACELOG) != 0) {
 362  389                      System.err.println("enabled");
 363  390                      System.err.print("GraphicsPrimitive timetamps ");
 364  391                      if ((traceflags & GraphicsPrimitive.TRACETIMESTAMP) != 0) {
 365  392                          System.err.println("enabled");
 366  393                      } else {
 367  394                          System.err.println("disabled");
 368  395                      }
↓ open down ↓ 40 lines elided ↑ open up ↑
 409  436                      traceout = System.err;
 410  437                  }
 411  438              } else {
 412  439                  traceout = System.err;
 413  440              }
 414  441          }
 415  442          return traceout;
 416  443      }
 417  444  
 418  445      public static class TraceReporter implements Runnable {
 419      -        public static void setShutdownHook() {
      446 +        private static boolean hookEnabled = false;
      447 +
      448 +        public static synchronized void setShutdownHook() {
      449 +            if (hookEnabled) return;
      450 +            hookEnabled = true;
      451 +
 420  452              AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 421  453                  TraceReporter t = new TraceReporter();
 422  454                  Thread thread = new Thread(
 423  455                          ThreadGroupUtils.getRootThreadGroup(), t,
 424  456                          "TraceReporter", 0, false);
 425  457                  thread.setContextClassLoader(null);
 426  458                  Runtime.getRuntime().addShutdownHook(thread);
 427  459                  return null;
 428  460              });
 429  461          }
 430  462  
 431  463          public void run() {
 432  464              PrintStream ps = getTraceOutputFile();
 433      -            Iterator<Map.Entry<Object, int[]>> iterator =
 434      -                traceMap.entrySet().iterator();
 435      -            long total = 0;
 436      -            int numprims = 0;
 437      -            while (iterator.hasNext()) {
 438      -                Map.Entry<Object, int[]> me = iterator.next();
 439      -                Object prim = me.getKey();
 440      -                int[] count = me.getValue();
 441      -                if (count[0] == 1) {
 442      -                    ps.print("1 call to ");
 443      -                } else {
 444      -                    ps.print(count[0]+" calls to ");
      465 +            if (traceMap != null) {
      466 +                Iterator<Map.Entry<Object, int[]>> iterator =
      467 +                        traceMap.entrySet().iterator();
      468 +                long total = 0;
      469 +                int numprims = 0;
      470 +                while (iterator.hasNext()) {
      471 +                    Map.Entry<Object, int[]> me = iterator.next();
      472 +                    Object prim = me.getKey();
      473 +                    int[] count = me.getValue();
      474 +                    if (count[0] == 1) {
      475 +                        ps.print("1 call to ");
      476 +                    } else {
      477 +                        ps.print(count[0] + " calls to ");
      478 +                    }
      479 +                    ps.println(prim);
      480 +                    numprims++;
      481 +                    total += count[0];
      482 +                }
      483 +                if (numprims == 0) {
      484 +                    ps.println("No graphics primitives executed");
      485 +                } else if (numprims > 1) {
      486 +                    ps.println(total + " total calls to " +
      487 +                            numprims + " different primitives");
 445  488                  }
 446      -                ps.println(prim);
 447      -                numprims++;
 448      -                total += count[0];
 449  489              }
 450      -            if (numprims == 0) {
 451      -                ps.println("No graphics primitives executed");
 452      -            } else if (numprims > 1) {
 453      -                ps.println(total+" total calls to "+
 454      -                           numprims+" different primitives");
      490 +
      491 +            if (traceNotImplSet != null) {
      492 +                ps.println("Not implemented graphics primitives:");
      493 +
      494 +                for (String name : traceNotImplSet) {
      495 +                    ps.println(name);
      496 +                }
 455  497              }
 456  498          }
 457  499      }
 458  500  
 459      -    public static synchronized void tracePrimitive(Object prim) {
      501 +    public synchronized static void tracePrimitive(Object prim) {
      502 +        if ((traceflags & TRACEPNAME) != 0) {
      503 +            if (!prim.toString().contains(pname)) return;
      504 +        }
      505 +
 460  506          if ((traceflags & TRACECOUNTS) != 0) {
 461  507              if (traceMap == null) {
 462  508                  traceMap = new HashMap<>();
 463  509                  TraceReporter.setShutdownHook();
 464  510              }
 465  511              int[] o = traceMap.get(prim);
 466  512              if (o == null) {
 467  513                  o = new int[1];
 468  514                  traceMap.put(prim, o);
 469  515              }
↓ open down ↓ 1 lines elided ↑ open up ↑
 471  517          }
 472  518          if ((traceflags & TRACELOG) != 0) {
 473  519              PrintStream ps = getTraceOutputFile();
 474  520              if ((traceflags & TRACETIMESTAMP) != 0) {
 475  521                  ps.print(System.currentTimeMillis()+": ");
 476  522              }
 477  523              ps.println(prim);
 478  524          }
 479  525      }
 480  526  
      527 +    public synchronized static void traceNotImplPrimitive(Object prim) {
      528 +        if ((traceflags & TRACEPNAME) != 0) {
      529 +            if (!prim.toString().contains(pname)) return;
      530 +        }
      531 +
      532 +        if ((traceflags & TRACECOUNTS) != 0) {
      533 +            if (traceNotImplSet == null) {
      534 +                traceNotImplSet = new HashSet<String>();
      535 +                TraceReporter.setShutdownHook();
      536 +            }
      537 +            traceNotImplSet.add(prim.toString());
      538 +        }
      539 +        if ((traceflags & TRACELOG) != 0) {
      540 +            PrintStream ps = getTraceOutputFile();
      541 +            if ((traceflags & TRACETIMESTAMP) != 0) {
      542 +                ps.print(System.currentTimeMillis()+":[NOT IMPL] ");
      543 +            }
      544 +            ps.println(prim);
      545 +        }
      546 +    }
      547 +
      548 +    public synchronized static void tracePrimitiveTime(Object prim, long time) {
      549 +        if ((traceflags & TRACEPNAME) != 0) {
      550 +            if (!prim.toString().contains(pname)) return;
      551 +        }
      552 +        if (time > treshold && (traceflags & TRACEPTIME) != 0  && (traceflags & TRACELOG) != 0) {
      553 +            PrintStream ps = getTraceOutputFile();
      554 +            ps.println(prim + " time: " + time);
      555 +            if (verbose) {
      556 +                final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
      557 +                if (stackTrace.length > 3) {
      558 +                    for (int i = 3; i < stackTrace.length; i++) {
      559 +                        ps.println("  " + stackTrace[i].toString());
      560 +                    }
      561 +                }
      562 +                ps.println();
      563 +            }
      564 +        }
      565 +    }
      566 +
 481  567      protected void setupGeneralBinaryOp(GeneralBinaryOp gbo) {
 482  568          int primID = gbo.getPrimTypeID();
 483  569          String methodSignature = gbo.getSignature();
 484  570          SurfaceType srctype = gbo.getSourceType();
 485  571          CompositeType comptype = gbo.getCompositeType();
 486  572          SurfaceType dsttype = gbo.getDestType();
 487  573          Blit convertsrc, convertdst, convertres;
 488  574          GraphicsPrimitive performop;
 489  575  
 490  576          convertsrc = createConverter(srctype, SurfaceType.IntArgb);
↓ open down ↓ 137 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX