public static void printElement(Site s, int index) { if (s == null || index >= s.site().length) { ps.print("(null)"); } else { StackTraceElement e = s.site()[index]; ps.print(e.getMethodName() + " (" + e.getFileName() + ":" + e.getLineNumber() + ")"); } }
public static void printSite(Site s, StringBuilder out) { if (s == null) { out.append("(null)"); return; } StackTraceElement[] st = s.site(); int interestingSitesPrinted = 0; for (int i = s.offset; i < st.length; i++) { StackTraceElement e = st[i]; String fileName = e.getFileName(); if (THIS_FILE_NAME.equals(fileName)) { continue; } out.append(" " + e.getMethodName() + "(" + e.getFileName() + ":" + e.getLineNumber() + ")"); interestingSitesPrinted++; if (interestingSitesPrinted <= SITES_TO_PRINT) { continue; } if (fileName == null || "View.java".equals(fileName)) { continue; } String methodName = e.getMethodName(); if (skipMethods.contains(methodName)) { continue; } break; } }
public static void printElements(Site s, int index, int nelems) { if (s == null || index >= s.site().length) { ps.print("(null)"); } else { for (int i = 0; i < nelems; i++) { int j = index + i; if (j >= s.site().length) { break; } if (i > 0) { ps.print(", "); } StackTraceElement e = s.site()[j]; ps.print(e.getMethodName() + " (" + e.getFileName() + ":" + e.getLineNumber() + ")"); } } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof Site)) { return false; } Site other = (Site) o; if (other.hashCode() != hashCode()) { return false; } StackTraceElement[] osite = other.site(); if (site.length != osite.length) { return false; } for (int i = offset; i < site.length; i++) { if (!site[i].equals(osite[i])) { return false; } } return true; }
private Site updateUseSite() { if (TRACE_USE_SITES) { Site here = new Site(); useSites.add(here); return here; } else if (TRACE_SINGLE_USE_SITE) { if (multipleUseSites) { return null; } else { Site here = new Site(); if (singleUseSite == null) { singleUseSite = here; } else { if (!here.equals(singleUseSite)) { multipleUseSites = true; singleUseSite = null; } } return here; } } else { return null; } }
private static void extractViewPattern(int depth, ViewTrace trace, StringBuilder p) { if (!processedViewsForPatterns.add(trace)) { p.append("(ALIASED) "); } p.append(trace.realView.getClass() + " size = " + trace.realView.size() + "\n"); indent(depth, p); p.append(" use:"); if (trace.materializeCount == 0 && trace.sumCount == 0 && trace.getCount == 0) { p.append(" UNUSED"); } else { if (trace.getCount > 0) { p.append(" get"); } if (trace.materializeCount > 0) { p.append(" materialize"); } if (trace.sumCount > 0) { p.append(" sum"); } } p.append("\n"); if (false) { p.append(" allocationSite ="); Site.printSite(trace.allocationSite, p); p.append("\n"); indent(depth, p); } RArray view = trace.realView; Class viewClass = view.getClass(); Field[] fields = getAllFields(viewClass); boolean printedField = false; for (Field f : fields) { if (f.isSynthetic()) { continue; } Class fieldClass = f.getType(); if (RArray.class.isAssignableFrom(fieldClass)) { continue; // these later } indent(depth, p); p.append(" " + f.getName() + " "); try { f.setAccessible(true); Object o = f.get(view); p.append(o == null ? "null (" + fieldClass + ")" : o.getClass()); p.append("\n"); printedField = true; } catch (IllegalAccessException e) { assert Utils.check(false, "can't read a view field " + e); } } boolean printNewline = printedField; for (Field f : fields) { if (f.isSynthetic()) { continue; } Class fieldClass = f.getType(); if (!RArray.class.isAssignableFrom(fieldClass)) { continue; } if (printNewline) { p.append("\n"); printNewline = false; } indent(depth, p); p.append(" " + f.getName() + " "); try { f.setAccessible(true); Object o = f.get(view); if (o instanceof TracingView) { p.append("VIEW "); TracingView child = (TracingView) o; extractViewPattern(depth + 2, child.getTrace(), p); } else { p.append("ARRAY " + o.getClass() + " size = " + ((RArray) o).size()); if (o instanceof View) { ps.println("MISSED VIEW " + o); } } p.append("\n"); } catch (IllegalAccessException e) { assert Utils.check(false, "can't read a view field " + e); } } }
private static void dumpView(int depth, ViewTrace trace) { printedIndividualViews.add(trace); ps.println(trace.realView + " size = " + trace.realView.size()); if (TRACE_ALLOCATION_SITE) { indent(depth); ps.print(" allocationSite ="); Site.printSite(trace.allocationSite); ps.println(); } int unused = trace.unusedElements(); int redundant = trace.redundantGets(); boolean singleUse; Site[] useSites; if (TRACE_USE_SITES) { useSites = trace.useSites.toArray(new Site[trace.useSites.size()]); singleUse = (useSites.length == 1); } else if (TRACE_SINGLE_USE_SITE) { useSites = null; singleUse = !trace.multipleUseSites; } else { useSites = null; singleUse = false; } if (singleUse) { indent(depth); ps.print(" singleUseSite = US"); Site.printSite(useSites != null ? useSites[0] : trace.singleUseSite); if (trace.getCount > 0) { ps.println(" (get)"); } else if (trace.sumCount > 0) { ps.println(" (sum)"); } else { ps.println(" (materialize)"); } } else if (trace.getCount > 0) { if (TRACE_FIRST_GET_SITE) { indent(depth); ps.print(" firstGetSite ="); Site.printSite(trace.firstGetSite); ps.println(); } if (trace.materializeCount == 0 && trace.sumCount == 0) { if (unused > 0) { indent(depth); ps.println(" unusedElements = " + unused); } if (redundant > 0) { indent(depth); ps.println(" redundantGets = " + redundant + " (no materialize, sum)"); } } } else { if (trace.materializeCount == 0 && trace.sumCount == 0) { indent(depth); ps.println(" UNUSED"); } else { indent(depth); ps.println( " materializeCount = " + trace.materializeCount + " sumCount = " + trace.sumCount + " getCount = " + trace.getCount); } } if (TRACE_FIRST_MATERIALIZE_SITE && trace.materializeCount > 0 && !singleUse) { indent(depth); ps.print(" firstMaterializeSite ="); Site.printSite(trace.firstMaterializeSite); ps.println(); } if (TRACE_FIRST_SUM_SITE && trace.sumCount > 0 && !singleUse) { indent(depth); ps.print(" firstSumSite ="); Site.printSite(trace.firstSumSite); ps.println(); } if (TRACE_USE_SITES) { if (useSites.length != 1) { indent(depth); ps.println(" useSites (" + useSites.length + "):"); for (Site s : useSites) { indent(depth); ps.print(" US"); Site.printSite(s); ps.println(); } } } ps.println(); RArray view = trace.realView; Class viewClass = view.getClass(); Field[] fields = getAllFields(viewClass); boolean printedField = false; for (Field f : fields) { if (f.isSynthetic()) { continue; } Class fieldClass = f.getType(); if (RArray.class.isAssignableFrom(fieldClass)) { continue; // these later } indent(depth); ps.print(" " + f.getName() + " "); try { f.setAccessible(true); ps.println(f.get(view)); printedField = true; } catch (IllegalAccessException e) { assert Utils.check(false, "can't read a view field " + e); } } boolean printNewline = printedField; for (Field f : fields) { if (f.isSynthetic()) { continue; } Class fieldClass = f.getType(); if (!RArray.class.isAssignableFrom(fieldClass)) { continue; } if (printNewline) { ps.println(); printNewline = false; } indent(depth); ps.print(" " + f.getName() + " "); try { f.setAccessible(true); Object o = f.get(view); if (o instanceof TracingView) { ps.print("VIEW "); TracingView child = (TracingView) o; dumpView(depth + 2, child.getTrace()); } else { ps.print("ARRAY " + o + " size = " + ((RArray) o).size()); if (o instanceof View) { ps.println("MISSED VIEW " + o); } } ps.println(); } catch (IllegalAccessException e) { assert Utils.check(false, "can't read a view field " + e); } } }