diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/BasicLogEvent.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/BasicLogEvent.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/BasicLogEvent.java Tue Mar 10 08:22:36 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -71,5 +71,5 @@ this.compilation = compilation; } - abstract public void print(PrintStream stream); + abstract public void print(PrintStream stream, boolean printID); } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/CallSite.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/CallSite.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/CallSite.java Tue Mar 10 08:22:36 2015 -0700 @@ -34,11 +34,14 @@ private Method method; private int count; private String receiver; - private int receiver_count; + private int receiverCount; + private String receiver2; + private int receiver2Count; private String reason; private List calls; private int endNodes; private double timeStamp; + private List traps; CallSite() { } @@ -66,9 +69,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); if (getReason() == null) { - sb.append(" @ " + getBci() + " " + getMethod()); + sb.append(" @ " + getBCI() + " " + getMethod()); } else { - sb.append("- @ " + getBci() + " " + getMethod() + " " + getReason()); + sb.append("- @ " + getBCI() + " " + getMethod() + " " + getReason()); } sb.append("\n"); if (getCalls() != null) { @@ -81,7 +84,7 @@ } public void print(PrintStream stream) { - print(stream, 0); + print(stream, 0, true, false); } void emit(PrintStream stream, int indent) { @@ -91,17 +94,17 @@ } private static boolean compat = true; - public void print(PrintStream stream, int indent) { + public void print(PrintStream stream, int indent, boolean printInlining, boolean printUncommonTraps) { emit(stream, indent); String m = getMethod().getHolder().replace('/', '.') + "::" + getMethod().getName(); if (getReason() == null) { - stream.print(" @ " + getBci() + " " + m + " (" + getMethod().getBytes() + " bytes)"); + stream.print(" @ " + getBCI() + " " + m + " (" + getMethod().getBytes() + " bytes)"); } else { if (isCompat()) { - stream.print(" @ " + getBci() + " " + m + " " + getReason()); + stream.print(" @ " + getBCI() + " " + m + " " + getReason()); } else { - stream.print("- @ " + getBci() + " " + m + + stream.print("- @ " + getBCI() + " " + m + " (" + getMethod().getBytes() + " bytes) " + getReason()); } } @@ -111,23 +114,31 @@ stream.println(""); if (getReceiver() != null) { emit(stream, indent + 4); - // stream.println("type profile " + method.holder + " -> " + receiver + " (" + - // receiver_count + "/" + count + "," + (receiver_count * 100 / count) + "%)"); stream.println("type profile " + getMethod().getHolder() + " -> " + getReceiver() + " (" + (getReceiverCount() * 100 / getCount()) + "%)"); + if (getReceiver2() != null) { + emit(stream, indent + 3); + stream.println("type profile " + getMethod().getHolder() + " -> " + getReceiver2() + " (" + + (getReceiver2Count() * 100 / getCount()) + "%)"); + } } - if (getCalls() != null) { + if (printInlining && getCalls() != null) { for (CallSite site : getCalls()) { + site.print(stream, indent + 2, printInlining, printUncommonTraps); + } + } + if (printUncommonTraps && getTraps() != null) { + for (UncommonTrap site : getTraps()) { site.print(stream, indent + 2); } } } - public int getBci() { + public int getBCI() { return bci; } - public void setBci(int bci) { + public void setBCI(int bci) { this.bci = bci; } @@ -156,11 +167,27 @@ } public int getReceiverCount() { - return receiver_count; + return receiverCount; } - public void setReceiver_count(int receiver_count) { - this.receiver_count = receiver_count; + public void setReceiverCount(int receiverCount) { + this.receiverCount = receiverCount; + } + + public String getReceiver2() { + return receiver2; + } + + public void setReceiver2(String receiver2) { + this.receiver2 = receiver2; + } + + public int getReceiver2Count() { + return receiver2Count; + } + + public void setReceiver2Count(int receiver2Count) { + this.receiver2Count = receiver2Count; } public String getReason() { @@ -179,6 +206,17 @@ this.calls = calls; } + public List getTraps() { + return traps; + } + + void add(UncommonTrap e) { + if (traps == null) { + traps = new ArrayList(); + } + traps.add(e); + } + public static boolean isCompat() { return compat; } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java Tue Mar 10 08:22:36 2015 -0700 @@ -26,15 +26,16 @@ import java.io.PrintStream; import java.util.ArrayList; +import java.util.List; public class Compilation implements LogEvent { - private int id; - private boolean osr; + private String id; + private int compileId; + private int bci; private Method method; private CallSite call = new CallSite(); private CallSite lateInlineCall = new CallSite(); - private int osrBci; private String icount; private String bcount; private String special; @@ -43,10 +44,16 @@ private int attempts; private NMethod nmethod; private ArrayList phases = new ArrayList(4); + private List events; private String failureReason; + private String compiler; + private double enqueueTime; - Compilation(int id) { - this.id = id; + Compilation(int id, int bci, String compiler) { + this.compileId = id; + this.bci = bci; + this.compiler = compiler; + this.id = compileId + ((bci == -1) ? "" : "%"); } Phase getPhase(String s) { @@ -66,10 +73,18 @@ return start; } + public double getEnqueueTime() { + return enqueueTime; + } + + public void setEnqueueTime(double e) { + enqueueTime = e; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(getId()); + sb.append(getCompileId()); sb.append(" "); sb.append(getMethod()); sb.append(" "); @@ -95,31 +110,41 @@ if (getMethod() == null) { stream.println(getSpecial()); } else { - int bc = isOsr() ? getOsr_bci() : -1; - stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); + int bc = getBCI(); + stream.print(getCompileId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); } } - public void print(PrintStream stream) { - print(stream, 0, false); + public void print(PrintStream stream, boolean printID) { + print(stream, 0, printID, true, false); } - public void print(PrintStream stream, boolean printInlining) { - print(stream, 0, printInlining); + public void print(PrintStream stream, boolean printID, + boolean printInlining, boolean printUncommonTraps) { + print(stream, 0, printID, printInlining, printUncommonTraps); } - public void print(PrintStream stream, int indent, boolean printInlining) { + public void print(PrintStream stream, int indent, boolean printID, + boolean printInlining, boolean printUncommonTraps) { if (getMethod() == null) { stream.println(getSpecial()); } else { - int bc = isOsr() ? getOsr_bci() : -1; - stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); + int bc = getBCI(); + if (printID) { + stream.print(getCompileId() + " "); + } + stream.print(getMethod().decodeFlags(bc) + " " + compiler + " " + getMethod().format(bc)); stream.println(); if (getFailureReason() != null) { - stream.println("COMPILE FAILED " + getFailureReason()); + stream.println("COMPILE SKIPPED: " + getFailureReason() + " (not retryable)"); } if (printInlining && call.getCalls() != null) { for (CallSite site : call.getCalls()) { + site.print(stream, indent + 2, printInlining, printUncommonTraps); + } + } + if (printUncommonTraps && call.getTraps() != null) { + for (UncommonTrap site : call.getTraps()) { site.print(stream, indent + 2); } } @@ -132,28 +157,24 @@ } } - public int getId() { + public int getCompileId() { + return compileId; + } + + public String getId() { return id; } - public void setId(int id) { - this.id = id; + public boolean isOsr() { + return bci != -1; } - public boolean isOsr() { - return osr; + public int getBCI() { + return bci; } - public void setOsr(boolean osr) { - this.osr = osr; - } - - public int getOsr_bci() { - return osrBci; - } - - public void setOsr_bci(int osrBci) { - this.osrBci = osrBci; + public String getCompiler() { + return compiler; } public String getIcount() { @@ -234,6 +255,7 @@ if (getMethod() == null) { this.method = method; } + call.setMethod(method); } public CallSite getCall() { @@ -255,4 +277,21 @@ public Compilation getCompilation() { return this; } + + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } + + void add(LogEvent e) { + if (getEvents() == null) { + setEvents(new ArrayList()); + } + getEvents().add(e); + } + + } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java Tue Mar 10 08:22:36 2015 -0700 @@ -29,18 +29,20 @@ package com.sun.hotspot.tools.compiler; -import java.io.PrintStream; +import java.io.*; import java.util.*; import org.xml.sax.*; import org.xml.sax.helpers.*; -public class LogCompilation extends DefaultHandler implements ErrorHandler, Constants { +public class LogCompilation { public static void usage(int exitcode) { System.out.println("Usage: LogCompilation [ -v ] [ -c ] [ -s ] [ -e | -N ] file1 ..."); System.out.println(" -c: clean up malformed 1.5 xml"); System.out.println(" -i: print inlining decisions"); System.out.println(" -S: print compilation statistics"); + System.out.println(" -U: print uncommon trap statistics"); + System.out.println(" -t: print with time stamps"); System.out.println(" -s: sort events by start time"); System.out.println(" -e: sort events by elapsed time"); System.out.println(" -N: sort events by name and start"); @@ -51,25 +53,42 @@ Comparator defaultSort = LogParser.sortByStart; boolean statistics = false; boolean printInlining = false; + boolean printUncommonTraps = false; boolean cleanup = false; + boolean trapHistory = false; + boolean compare = false; + boolean printTimeStamps = false; + boolean printID = true; int index = 0; while (args.length > index) { if (args[index].equals("-e")) { defaultSort = LogParser.sortByElapsed; index++; - } else if (args[index].equals("-n")) { + } else if (args[index].equals("-N")) { defaultSort = LogParser.sortByNameAndStart; index++; } else if (args[index].equals("-s")) { defaultSort = LogParser.sortByStart; index++; + } else if (args[index].equals("-t")) { + printTimeStamps = true; + index++; } else if (args[index].equals("-c")) { cleanup = true; index++; + } else if (args[index].equals("-C")) { + compare = true; + index++; + } else if (args[index].equals("-n")) { + printID = false; + index++; } else if (args[index].equals("-S")) { statistics = true; index++; + } else if (args[index].equals("-U")) { + trapHistory = true; + index++; } else if (args[index].equals("-h")) { usage(0); } else if (args[index].equals("-i")) { @@ -84,19 +103,33 @@ usage(1); } + if (compare) { + compareLogs(index, args); + return; + } + while (index < args.length) { ArrayList events = LogParser.parse(args[index], cleanup); if (statistics) { printStatistics(events, System.out); + } else if (trapHistory) { + printTrapHistory(events, System.out); } else { Collections.sort(events, defaultSort); for (LogEvent c : events) { - if (printInlining && c instanceof Compilation) { + if (c instanceof NMethod) { + // skip these + continue; + } + if (printTimeStamps) { + System.out.print(c.getStart() + ": "); + } + if (c instanceof Compilation) { Compilation comp = (Compilation)c; - comp.print(System.out, true); + comp.print(System.out, printID, printInlining, printUncommonTraps); } else { - c.print(System.out); + c.print(System.out, printID); } } } @@ -104,6 +137,249 @@ } } + static class MethodBCIPair { + public MethodBCIPair(Method m, int b, String c) { + method = m; + bci = b; + compiler = c; + } + + Method method; + int bci; + String compiler; + + public boolean equals(Object other) { + if (!(other instanceof MethodBCIPair)) { + return false; + } + MethodBCIPair otherp = (MethodBCIPair)other; + return (otherp.bci == bci && + otherp.method.equals(method) && + otherp.compiler.equals(compiler)); + } + + public int hashCode() { + return method.hashCode() + bci; + } + + public String toString() { + if (bci != -1) { + return method + "@" + bci + " (" + compiler + ")"; + } else { + return method + " (" + compiler + ")"; + } + } + } + + static void compareLogs(int index, String[] args) throws Exception { + HashMap methods = new HashMap(); + ArrayList> logs = new ArrayList>(); + PrintStream[] outs = new PrintStream[args.length - index]; + PrintStream summary = new PrintStream(new FileOutputStream("summary.txt")); + int o = 0; + while (index < args.length) { + String basename = new File(args[index]).getName(); + String outname = "sorted-" + basename; + System.out.println("Sorting " + basename + " to " + outname); + outs[o] = new PrintStream(new FileOutputStream(outname)); + o++; + System.out.println("Parsing " + args[index]); + ArrayList events = LogParser.parse(args[index], false); + HashMap compiles = new HashMap(); + logs.add(compiles); + for (LogEvent c : events) { + if (c instanceof Compilation) { + Compilation comp = (Compilation)c; + MethodBCIPair key = new MethodBCIPair(comp.getMethod(), comp.getBCI(), + comp.getCompiler()); + MethodBCIPair e = methods.get(key); + if (e == null) { + methods.put(key, key); + } else { + key = e; + } + Object other = compiles.get(key); + if (other == null) { + compiles.put(key, comp); + } else { + if (!(other instanceof List)) { + List l = new LinkedList(); + l.add(other); + l.add(comp); + compiles.put(key, l); + } else { + List l = (List) other; + l.add(comp); + } + } + } + } + index++; + } + for (MethodBCIPair pair: methods.keySet()) { + summary.print(pair + " "); + int base = -1; + String first = null; + boolean mismatch = false; + boolean different = false; + String[] output = new String[outs.length]; + o = 0; + for (HashMap set: logs) { + Object e = set.get(pair); + String thisone = null; + Compilation lastc = null; + int n; + if (e == null) n = 0; + else if (e instanceof Compilation) { + n = 1; + lastc = (Compilation)e; + } else { + // Compare the last compilation that was done for this method + n = ((List)e).size(); + lastc = (Compilation)((List)e).get(n - 1); + } + if (lastc != null) { + n = 1; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + lastc.print(ps, false); + ps.close(); + thisone = new String(baos.toByteArray()); + } + if (base == -1) { + base = n; + } else if (base != n) { + mismatch = true; + } + output[o++] = thisone; + if (thisone != null) { + if (first == null) { + first = thisone; + } else { + if (!first.equals(thisone)) { + different = true; + } + } + } + if (different) { + summary.print(n + "d "); + } else { + summary.print(n + " "); + } + } + if (mismatch) { + summary.print("mismatch"); + } + summary.println(); + if (different) { + for (int i = 0; i < outs.length; i++) { + if (output[i] != null) { + outs[i].println(output[i]); + } + } + } + } + for (int i = 0; i < outs.length; i++) { + outs[i].close(); + } + if (summary != System.out) { + summary.close(); + } + } + + public static void printTrapHistory(ArrayList events, PrintStream out) { + LinkedHashMap> traps = new LinkedHashMap>(); + HashMap comps = new HashMap(); + for (LogEvent e : events) { + if (e instanceof NMethod) { + // skip these + continue; + } + if (e instanceof Compilation) { + Compilation c = (Compilation)e; + String name = c.getMethod().getFullName(); + ArrayList elist = traps.get(name); + if (elist != null && + comps.get(c.getId()) == null) { + comps.put(c.getId(), c); + // If there were previous events for the method + // then keep track of later compiles too. + elist.add(c); + } + continue; + } + if (e instanceof BasicLogEvent) { + BasicLogEvent ble = (BasicLogEvent)e; + Compilation c = ble.getCompilation(); + if (c == null) { + if (!(ble instanceof NMethod)) { + throw new InternalError(); + } + continue; + } + String name = c.getMethod().getFullName(); + ArrayList elist = traps.get(name); + if (elist == null) { + elist = new ArrayList(); + traps.put(name, elist); + } + if (comps.get(ble.getId()) == null) { + comps.put(ble.getId(), c); + // Add the associated compile to the list. It + // will likely go at the end but we need to search + // backwards for the proper insertion point. + double start = c.getStart(); + int ipoint = 0; + while (ipoint < elist.size() && elist.get(ipoint).getStart() < start) { + ipoint++; + } + if (ipoint == elist.size()) { + elist.add(c); + } else { + elist.add(ipoint, c); + } + } + elist.add(ble); + } + } + for (String c: traps.keySet()) { + ArrayList elist = traps.get(c); + String name = ((Compilation)elist.get(0)).getMethod().getFullName(); + System.out.println(name); + double start = 0; + for (LogEvent e: elist) { + if (start > e.getStart() && e.getStart() != 0) { + throw new InternalError(); + } + start = e.getStart(); + out.print(e.getStart() + ": "); + if (e instanceof Compilation) { + ((Compilation)e).print(out, true, true, true); + } else { + e.print(out, true); + } + } + out.println(); + } + } + + static enum QueueState { + ENQUEUE, START, END; + } + + static class QueueEvent { + + Compilation compilation; + double time; + QueueState state; + + QueueEvent(Compilation c, double t, QueueState s) { + compilation = c; + time = t; + state = s; + } + } + public static void printStatistics(ArrayList events, PrintStream out) { long cacheSize = 0; long maxCacheSize = 0; @@ -117,11 +393,60 @@ LinkedHashMap phaseNodes = new LinkedHashMap(7); double elapsed = 0; + + ArrayList queue = new ArrayList(); for (LogEvent e : events) { if (e instanceof Compilation) { Compilation c = (Compilation) e; - c.printShort(out); - out.printf(" %6.4f\n", c.getElapsedTime()); + queue.add(new QueueEvent(c, c.getStart(), QueueState.START)); + queue.add(new QueueEvent(c, c.getEnd(), QueueState.END)); + queue.add(new QueueEvent(c, c.getEnqueueTime(), QueueState.ENQUEUE)); + } + } + Collections.sort(queue, new Comparator() { + public int compare(QueueEvent a, QueueEvent b) { + double difference = (a.time - b.time); + if (difference < 0) { + return -1; + } + if (difference > 0) { + return 1; + } + return a.state.compareTo(b.state); + } + }); + + LinkedList activeCompiles = new LinkedList(); + LinkedList compileQueue = new LinkedList(); + int maxQueueLength = 0; + + for (QueueEvent e: queue) { + if (e.state == QueueState.START) { + compileQueue.remove(e.compilation); + activeCompiles.add(e.compilation); + } else if (e.state == QueueState.END) { + activeCompiles.remove(e.compilation); + } else if (e.state == QueueState.ENQUEUE) { + compileQueue.add(e.compilation); + } + maxQueueLength = Math.max(maxQueueLength, compileQueue.size()); + System.out.println(e.time + " " + e.compilation.getId() + " " + e.state + " " + activeCompiles.size() + " " + compileQueue.size()); + } + + PriorityQueue topCompiles = new PriorityQueue(11, LogParser.sortByElapsed); + int totalCompiles = 0; + for (LogEvent e : events) { + if (e instanceof Compilation) { + Compilation c = (Compilation) e; + totalCompiles++; + + topCompiles.add(c); + while (topCompiles.size() > 30) { + topCompiles.poll(); + } + + // c.printShort(out); + // out.printf(" %6.4f\n", c.getElapsedTime()); attempts[c.getAttempts()]++; maxattempts = Math.max(maxattempts,c.getAttempts()); elapsed += c.getElapsedTime(); @@ -158,14 +483,22 @@ } } out.printf("NMethods: %d created %d live %d bytes (%d peak) in the code cache\n", - nmethodsCreated, nmethodsLive, cacheSize, maxCacheSize); + nmethodsCreated, nmethodsLive, cacheSize, maxCacheSize); out.println("Phase times:"); for (String name : phaseTime.keySet()) { Double v = phaseTime.get(name); Integer v2 = phaseNodes.get(name); out.printf("%20s %6.4f %d\n", name, v.doubleValue(), v2.intValue()); } - out.printf("%20s %6.4f\n", "total", elapsed); + out.printf("%20s %6.4f\n", "total compile time", elapsed); + + out.printf("%20s %d\n", "max queue length", maxQueueLength); + + out.println("longest compiles"); + while (topCompiles.size() > 0) { + Compilation c = topCompiles.poll(); + out.printf(" %s %6.4f\n", c.getId(), c.getElapsedTime()); + } if (maxattempts > 0) { out.println("Distribution of regalloc passes:"); diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogEvent.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogEvent.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogEvent.java Tue Mar 10 08:22:36 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,5 +34,5 @@ public Compilation getCompilation(); - public void print(PrintStream stream); + public void print(PrintStream stream, boolean printID); } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java Tue Mar 10 08:22:36 2015 -0700 @@ -29,6 +29,7 @@ package com.sun.hotspot.tools.compiler; +import java.io.BufferedReader; import java.io.FileReader; import java.io.Reader; import java.util.ArrayList; @@ -37,23 +38,245 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Stack; +import java.util.regex.Pattern; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; +import org.xml.sax.Locator; import org.xml.sax.helpers.DefaultHandler; public class LogParser extends DefaultHandler implements ErrorHandler, Constants { - static final HashMap typeMap; + static final Pattern spacePattern = Pattern.compile(" "); + static final HashMap type2printableMap; + static final HashMap type2vmtypeMap; + + static String[] bytecodes = new String[] { + "nop", + "aconst_null", + "iconst_m1", + "iconst_0", + "iconst_1", + "iconst_2", + "iconst_3", + "iconst_4", + "iconst_5", + "lconst_0", + "lconst_1", + "fconst_0", + "fconst_1", + "fconst_2", + "dconst_0", + "dconst_1", + "bipush", + "sipush", + "ldc", + "ldc_w", + "ldc2_w", + "iload", + "lload", + "fload", + "dload", + "aload", + "iload_0", + "iload_1", + "iload_2", + "iload_3", + "lload_0", + "lload_1", + "lload_2", + "lload_3", + "fload_0", + "fload_1", + "fload_2", + "fload_3", + "dload_0", + "dload_1", + "dload_2", + "dload_3", + "aload_0", + "aload_1", + "aload_2", + "aload_3", + "iaload", + "laload", + "faload", + "daload", + "aaload", + "baload", + "caload", + "saload", + "istore", + "lstore", + "fstore", + "dstore", + "astore", + "istore_0", + "istore_1", + "istore_2", + "istore_3", + "lstore_0", + "lstore_1", + "lstore_2", + "lstore_3", + "fstore_0", + "fstore_1", + "fstore_2", + "fstore_3", + "dstore_0", + "dstore_1", + "dstore_2", + "dstore_3", + "astore_0", + "astore_1", + "astore_2", + "astore_3", + "iastore", + "lastore", + "fastore", + "dastore", + "aastore", + "bastore", + "castore", + "sastore", + "pop", + "pop2", + "dup", + "dup_x1", + "dup_x2", + "dup2", + "dup2_x1", + "dup2_x2", + "swap", + "iadd", + "ladd", + "fadd", + "dadd", + "isub", + "lsub", + "fsub", + "dsub", + "imul", + "lmul", + "fmul", + "dmul", + "idiv", + "ldiv", + "fdiv", + "ddiv", + "irem", + "lrem", + "frem", + "drem", + "ineg", + "lneg", + "fneg", + "dneg", + "ishl", + "lshl", + "ishr", + "lshr", + "iushr", + "lushr", + "iand", + "land", + "ior", + "lor", + "ixor", + "lxor", + "iinc", + "i2l", + "i2f", + "i2d", + "l2i", + "l2f", + "l2d", + "f2i", + "f2l", + "f2d", + "d2i", + "d2l", + "d2f", + "i2b", + "i2c", + "i2s", + "lcmp", + "fcmpl", + "fcmpg", + "dcmpl", + "dcmpg", + "ifeq", + "ifne", + "iflt", + "ifge", + "ifgt", + "ifle", + "if_icmpeq", + "if_icmpne", + "if_icmplt", + "if_icmpge", + "if_icmpgt", + "if_icmple", + "if_acmpeq", + "if_acmpne", + "goto", + "jsr", + "ret", + "tableswitch", + "lookupswitch", + "ireturn", + "lreturn", + "freturn", + "dreturn", + "areturn", + "return", + "getstatic", + "putstatic", + "getfield", + "putfield", + "invokevirtual", + "invokespecial", + "invokestatic", + "invokeinterface", + "invokedynamic", + "new", + "newarray", + "anewarray", + "arraylength", + "athrow", + "checkcast", + "instanceof", + "monitorenter", + "monitorexit", + "wide", + "multianewarray", + "ifnull", + "ifnonnull", + "goto_w", + "jsr_w", + "breakpoint" + }; + static { - typeMap = new HashMap(); - typeMap.put("[I", "int[]"); - typeMap.put("[C", "char[]"); - typeMap.put("[Z", "boolean[]"); - typeMap.put("[L", "Object[]"); - typeMap.put("[B", "byte[]"); + type2printableMap = new HashMap(); + type2printableMap.put("[I", "int[]"); + type2printableMap.put("[C", "char[]"); + type2printableMap.put("[Z", "boolean[]"); + type2printableMap.put("[L", "Object[]"); + type2printableMap.put("[B", "byte[]"); + + type2vmtypeMap = new HashMap(); + type2vmtypeMap.put("void", "V"); + type2vmtypeMap.put("boolean", "Z"); + type2vmtypeMap.put("byte", "B"); + type2vmtypeMap.put("char", "C"); + type2vmtypeMap.put("short", "S"); + type2vmtypeMap.put("int", "I"); + type2vmtypeMap.put("long", "J"); + type2vmtypeMap.put("float", "F"); + type2vmtypeMap.put("double", "D"); } static Comparator sortByStart = new Comparator() { @@ -79,6 +302,37 @@ return 7; } }; + static Comparator sortByEnd = new Comparator() { + + public int compare(LogEvent a, LogEvent b) { + double t1 = a.getStart(); + double t2 = b.getStart(); + if (a instanceof Compilation) { + t1 = ((Compilation)a).getEnd(); + } + if (b instanceof Compilation) { + t2 = ((Compilation)b).getEnd(); + } + double difference = t1 - t2; + if (difference < 0) { + return -1; + } + if (difference > 0) { + return 1; + } + return 0; + } + + @Override + public boolean equals(Object other) { + return false; + } + + @Override + public int hashCode() { + return 7; + } + }; static Comparator sortByNameAndStart = new Comparator() { public int compare(LogEvent a, LogEvent b) { @@ -132,6 +386,37 @@ return 7; } }; + static Comparator sortByEnqueueTime = new Comparator() { + + public int compare(LogEvent a, LogEvent b) { + double t1 = a.getStart(); + double t2 = b.getStart(); + if (a instanceof Compilation) { + t1 = ((Compilation)a).getEnqueueTime(); + } + if (b instanceof Compilation) { + t2 = ((Compilation)b).getEnqueueTime(); + } + double difference = t1 - t2; + if (difference < 0) { + return -1; + } + if (difference > 0) { + return 1; + } + return 0; + } + + @Override + public boolean equals(Object other) { + return false; + } + + @Override + public int hashCode() { + return 7; + } + }; private ArrayList events = new ArrayList(); @@ -139,39 +424,53 @@ private HashMap methods = new HashMap(); private LinkedHashMap nmethods = new LinkedHashMap(); private HashMap compiles = new HashMap(); + private HashMap enqueueTime = new HashMap(); private String failureReason; - private int bci; + private int current_bci; + private int current_bytecode; private Stack scopes = new Stack(); private Compilation compile; private CallSite site; private Stack phaseStack = new Stack(); private UncommonTrapEvent currentTrap; private Stack late_inline_scope; + private JVMSLogEvent withJVMS; + private boolean inLateInline = false; - long parseLong(String l) { - try { - return Long.decode(l).longValue(); - } catch (NumberFormatException nfe) { - int split = l.length() - 8; - String s1 = "0x" + l.substring(split); - String s2 = l.substring(0, split); - long v1 = Long.decode(s1).longValue() & 0xffffffffL; - long v2 = (Long.decode(s2).longValue() & 0xffffffffL) << 32; - if (!l.equals("0x" + Long.toHexString(v1 + v2))) { - System.out.println(l); - System.out.println(s1); - System.out.println(s2); - System.out.println(v1); - System.out.println(v2); - System.out.println(Long.toHexString(v1 + v2)); - throw new InternalError("bad conversion"); - } - return v1 + v2; + private void reportInternalError(String msg) { + reportInternalError(msg, null); + } + + private void reportInternalError(String msg, Exception e) { + if (locator != null) { + msg = msg + " at " + locator.getLineNumber() + ":" + locator.getColumnNumber(); + } + if (e != null) { + throw new Error(msg, e); + } else { + throw new Error(msg); } } + static long parseULong(String l) { + if (!l.startsWith("0x")) { + throw new InternalError("malformed ulong: " + l); + } + long value = 0; + for (int i = 2; i < l.length(); i++) { + value <<= 4; + char c = l.charAt(i); + if (c >= '0' && c <= '9') value += c - '0'; + else if (c >= 'a' && c <= 'f') value += c - 'a' + 10; + else if (c >= 'A' && c <= 'F') value += c - 'A' + 10; + else + throw new InternalError("unexpected character in ulong: " + c + " in " + l); + } + return value; + } + public static ArrayList parse(String file, boolean cleanup) throws Exception { - return parse(new FileReader(file), cleanup); + return parse(new BufferedReader(new FileReader(file), 32 * 1024), cleanup); } public static ArrayList parse(Reader reader, boolean cleanup) throws Exception { @@ -190,13 +489,22 @@ LogParser log = new LogParser(); p.parse(new InputSource(reader), log); - // Associate compilations with their NMethods - for (NMethod nm : log.nmethods.values()) { - Compilation c = log.compiles.get(nm.getId()); - nm.setCompilation(c); - // Native wrappers for methods don't have a compilation - if (c != null) { - c.setNMethod(nm); + // Associate compilations with their NMethods and other kinds of events + for (LogEvent e : log.events) { + if (e instanceof BasicLogEvent) { + BasicLogEvent ble = (BasicLogEvent)e; + Compilation c = log.compiles.get(ble.getId()); + if (c == null) { + // Should only happen for native compiles + if (!(ble instanceof NMethod)) { + throw new InternalError(); + } + continue; + } + ble.setCompilation(c); + if (ble instanceof NMethod) { + c.setNMethod((NMethod)ble); + } } } @@ -221,23 +529,38 @@ for (int i = 0; i < attr.getLength(); i++) { System.out.println(attr.getQName(i) + " " + attr.getValue(attr.getQName(i))); } - throw new InternalError("can't find " + name); + reportInternalError("can't find " + name); + return null; } - int indent = 0; String compile_id; String type(String id) { String result = types.get(id); if (result == null) { - throw new InternalError(id); + reportInternalError(id); } - String remapped = typeMap.get(result); + String remapped = type2printableMap.get(result); if (remapped != null) { return remapped; } return result; } + String sigtype(String id) { + String result = types.get(id); + String remapped = type2vmtypeMap.get(result); + if (remapped != null) { + return remapped; + } + if (result == null) { + reportInternalError(id); + } + if (result.charAt(0) == '[') { + return result; + } + return "L" + result + ";"; + } + void type(String id, String name) { assert type(id) == null; types.put(id, name); @@ -246,14 +569,14 @@ Method method(String id) { Method result = methods.get(id); if (result == null) { - throw new InternalError(id); + reportInternalError(id); } return result; } public String makeId(Attributes atts) { String id = atts.getValue("compile_id"); - String kind = atts.getValue("kind"); + String kind = atts.getValue("compile_kind"); if (kind != null && kind.equals("osr")) { id += "%"; } @@ -261,14 +584,14 @@ } @Override - public void startElement(String uri, - String localName, - String qname, - Attributes atts) { + public void startElement(String uri, + String localName, + String qname, + Attributes atts) { if (qname.equals("phase")) { Phase p = new Phase(search(atts, "name"), - Double.parseDouble(search(atts, "stamp")), - Integer.parseInt(search(atts, "nodes"))); + Double.parseDouble(search(atts, "stamp")), + Integer.parseInt(search(atts, "nodes"))); phaseStack.push(p); } else if (qname.equals("phase_done")) { Phase p = phaseStack.pop(); @@ -276,38 +599,62 @@ p.setEnd(Double.parseDouble(search(atts, "stamp"))); compile.getPhases().add(p); } else if (qname.equals("task")) { - compile = new Compilation(Integer.parseInt(search(atts, "compile_id", "-1"))); - compile.setStart(Double.parseDouble(search(atts, "stamp"))); - compile.setICount(search(atts, "count", "0")); - compile.setBCount(search(atts, "backedge_count", "0")); + String id = makeId(atts); + if (id != null && compiles.get(id) != null) { + reportInternalError("duplicate id: " + id); + } + int compileId = Integer.parseInt(search(atts, "compile_id", "-1")); + int bci = Integer.parseInt(search(atts, "osr_bci", "-1")); - String method = atts.getValue("method"); - int space = method.indexOf(' '); - method = method.substring(0, space) + "::" + - method.substring(space + 1, method.indexOf(' ', space + 1) + 1); - String compiler = atts.getValue("compiler"); - if (compiler == null) { - compiler = ""; - } + String[] parts = spacePattern.split(atts.getValue("method")); + String methodName = parts[0] + "::" + parts[1]; String kind = atts.getValue("compile_kind"); if (kind == null) { kind = "normal"; } + String special; if (kind.equals("osr")) { - compile.setOsr(true); - compile.setOsr_bci(Integer.parseInt(search(atts, "osr_bci"))); + special = null; + // nothing to do } else if (kind.equals("c2i")) { - compile.setSpecial("--- adapter " + method); + special = "--- adapter " + methodName; } else { - compile.setSpecial(compile.getId() + " " + method + " (0 bytes)"); + special = compileId + " " + methodName + " (0 bytes)"; } + + + // Build a dummy method to stuff in the Compilation at the beginning + Method m = new Method(); + m.setHolder(parts[0]); + m.setName(parts[1]); + m.setSignature(parts[2]); + m.setFlags("0"); + m.setBytes("unknown"); + + String compiler = ""; + NMethod nm = nmethods.get(id); + if (nm != null) { + compiler = nm.getCompiler(); + } else { + // System.err.println("Can't find nmethod for " + id); + } + + compile = new Compilation(compileId, bci, compiler); + compile.setStart(Double.parseDouble(search(atts, "stamp"))); + compile.setEnqueueTime(enqueueTime.get(id).doubleValue()); + enqueueTime.remove(id); + compile.setICount(search(atts, "count", "0")); + compile.setBCount(search(atts, "backedge_count", "0")); + compile.setMethod(m); + compile.setSpecial(special); events.add(compile); - compiles.put(makeId(atts), compile); + compiles.put(id, compile); site = compile.getCall(); } else if (qname.equals("type")) { type(search(atts, "id"), search(atts, "name")); } else if (qname.equals("bc")) { - bci = Integer.parseInt(search(atts, "bci")); + current_bci = Integer.parseInt(search(atts, "bci")); + current_bytecode = Integer.parseInt(search(atts, "code")); } else if (qname.equals("klass")) { type(search(atts, "id"), search(atts, "name")); } else if (qname.equals("method")) { @@ -316,18 +663,35 @@ m.setHolder(type(search(atts, "holder"))); m.setName(search(atts, "name")); m.setReturnType(type(search(atts, "return"))); - m.setArguments(search(atts, "arguments", "void")); + String arguments = atts.getValue("arguments");; + if (arguments == null) { + m.setSignature("()" + sigtype(atts.getValue("return"))); + } else { + String[] args = spacePattern.split(arguments); + StringBuilder sb = new StringBuilder("("); + for (int i = 0; i < args.length; i++) { + sb.append(sigtype(args[i])); + } + sb.append(")"); + sb.append(sigtype(atts.getValue("return"))); + m.setSignature(sb.toString()); + } m.setBytes(search(atts, "bytes")); m.setIICount(search(atts, "iicount")); m.setFlags(search(atts, "flags")); methods.put(id, m); } else if (qname.equals("call")) { - site = new CallSite(bci, method(search(atts, "method"))); + site = new CallSite(current_bci, method(search(atts, "method"))); site.setCount(Integer.parseInt(search(atts, "count"))); String receiver = atts.getValue("receiver"); if (receiver != null) { site.setReceiver(type(receiver)); - site.setReceiver_count(Integer.parseInt(search(atts, "receiver_count"))); + site.setReceiverCount(Integer.parseInt(search(atts, "receiver_count"))); + String receiver2 = atts.getValue("receiver2"); + if (receiver2 != null && !receiver2.equals("-1")) { + site.setReceiver2(type(receiver2)); + site.setReceiver2Count(Integer.parseInt(search(atts, "receiver2_count"))); + } } scopes.peek().add(site); } else if (qname.equals("regalloc")) { @@ -344,23 +708,58 @@ } else if (qname.equals("make_not_entrant")) { String id = makeId(atts); NMethod nm = nmethods.get(id); - if (nm == null) throw new InternalError(); - LogEvent e = new MakeNotEntrantEvent(Double.parseDouble(search(atts, "stamp")), id, - atts.getValue("zombie") != null, nm); - events.add(e); + if (nm != null) { + LogEvent e = new MakeNotEntrantEvent(Double.parseDouble(search(atts, "stamp")), id, + atts.getValue("zombie") != null, nm); + events.add(e); + } + } else if (qname.equals("eliminate_allocation")) { + withJVMS = new EliminatedAllocation(compile, + type(search(atts, "type"))); + compile.add(withJVMS); + } else if (qname.equals("eliminate_lock")) { + if (search(atts, "lock").equals("1")) { + // unlocks don't have jvms so ignore them + withJVMS = new EliminatedLock(compile); + compile.add(withJVMS); + } + } else if (qname.equals("replace_string_concat")) { + withJVMS = new StringConcat(compile, + Integer.parseInt(search(atts, "arguments")), + Integer.parseInt(search(atts, "multiple")) != 0, + Integer.parseInt(search(atts, "string_alloc")) != 0); + compile.add(withJVMS); + } else if (qname.equals("late_inline")) { + inLateInline = true; } else if (qname.equals("uncommon_trap")) { String id = atts.getValue("compile_id"); if (id != null) { id = makeId(atts); currentTrap = new UncommonTrapEvent(Double.parseDouble(search(atts, "stamp")), - id, - atts.getValue("reason"), - atts.getValue("action"), - Integer.parseInt(search(atts, "count", "0"))); + id, + atts.getValue("reason"), + atts.getValue("action"), + Integer.parseInt(search(atts, "count", "0"))); events.add(currentTrap); } else { - // uncommon trap inserted during parsing. - // ignore for now + // compile.printShort(System.err); + if (atts.getValue("method") != null) { + // These are messages from ciTypeFlow that don't + // actually correspond to generated code. + return; + } + try { + // scopes.peek().print(System.err, 0); + if (scopes.size() == 0) { + reportInternalError("scope underflow"); + } + scopes.peek().add(new UncommonTrap(Integer.parseInt(search(atts, "bci")), + search(atts, "reason"), + search(atts, "action"), + bytecodes[current_bytecode])); + } catch (Error e) { + e.printStackTrace(); + } } } else if (qname.equals("late_inline")) { late_inline_scope = new Stack(); @@ -369,22 +768,28 @@ } else if (qname.equals("jvms")) { // if (currentTrap != null) { - currentTrap.addJVMS(atts.getValue("method"), Integer.parseInt(atts.getValue("bci"))); + String[] parts = spacePattern.split(atts.getValue("method")); + currentTrap.addMethodAndBCI(parts[0].replace('/', '.') + '.' + parts[1] + parts[2], + Integer.parseInt(atts.getValue("bci"))); } else if (late_inline_scope != null) { bci = Integer.parseInt(search(atts, "bci")); site = new CallSite(bci, method(search(atts, "method"))); late_inline_scope.push(site); - } else { - // Ignore , - // , - // + } else if (withJVMS != null) { + Method m = method(search(atts, "method")); + String s = m.getHolder() + " " + m.getName() + " " + m.getArguments(); + withJVMS.addMethodAndBCI(s, Integer.parseInt(atts.getValue("bci"))); + } else if (!inLateInline) { + reportInternalError("Missing uncommon_trap for jvms"); } } else if (qname.equals("nmethod")) { String id = makeId(atts); + // System.err.println(id + " " + atts.getValue("compiler")); NMethod nm = new NMethod(Double.parseDouble(search(atts, "stamp")), - id, - parseLong(atts.getValue("address")), - parseLong(atts.getValue("size"))); + id, + parseULong(atts.getValue("address")), + Long.parseLong(atts.getValue("size")), + atts.getValue("compiler")); nmethods.put(id, nm); events.add(nm); } else if (qname.equals("parse")) { @@ -400,7 +805,7 @@ } else { System.out.println(site.getMethod()); System.out.println(m); - throw new InternalError("call site and parse don't match"); + reportInternalError("call site and parse don't match"); } } } else if (qname.equals("parse_done")) { @@ -408,18 +813,21 @@ call.setEndNodes(Integer.parseInt(search(atts, "nodes", "1"))); call.setTimeStamp(Double.parseDouble(search(atts, "stamp"))); scopes.push(call); + } else if (qname.equals("task_queued")) { + String id = makeId(atts); + enqueueTime.put(id, Double.parseDouble(search(atts, "stamp"))); } } @Override - public void endElement(String uri, - String localName, - String qname) { - if (qname.equals("parse")) { - indent -= 2; - scopes.pop(); - } else if (qname.equals("uncommon_trap")) { - currentTrap = null; + public void endElement(String uri, + String localName, + String qname) { + try { + if (qname.equals("parse")) { + scopes.pop(); + } else if (qname.equals("uncommon_trap")) { + currentTrap = null; } else if (qname.equals("late_inline")) { // Populate late inlining info. @@ -457,27 +865,43 @@ // late_inline is followed by parse with scopes.size() == 0, // 'site' will be pushed to scopes. late_inline_scope = null; - } else if (qname.equals("task")) { - types.clear(); - methods.clear(); - site = null; + } else if (qname.equals("eliminate_allocation")) { + withJVMS = null; + } else if (qname.equals("eliminate_lock")) { + withJVMS = null; + } else if (qname.equals("replace_string_concat")) { + withJVMS = null; + } else if (qname.equals("late_inline")) { + inLateInline = false; + } else if (qname.equals("task")) { + types.clear(); + methods.clear(); + site = null; + } + } catch (Exception e) { + reportInternalError("exception while processing end element", e); } } + Locator locator; + @Override public void setDocumentLocator(Locator locator) { + this.locator = locator; + } + @Override - public void warning(org.xml.sax.SAXParseException e) { + public void warning(org.xml.sax.SAXParseException e) { System.err.println(e.getMessage() + " at line " + e.getLineNumber() + ", column " + e.getColumnNumber()); e.printStackTrace(); } @Override - public void error(org.xml.sax.SAXParseException e) { + public void error(org.xml.sax.SAXParseException e) { System.err.println(e.getMessage() + " at line " + e.getLineNumber() + ", column " + e.getColumnNumber()); e.printStackTrace(); } @Override - public void fatalError(org.xml.sax.SAXParseException e) { + public void fatalError(org.xml.sax.SAXParseException e) { System.err.println(e.getMessage() + " at line " + e.getLineNumber() + ", column " + e.getColumnNumber()); e.printStackTrace(); } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/MakeNotEntrantEvent.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/MakeNotEntrantEvent.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/MakeNotEntrantEvent.java Tue Mar 10 08:22:36 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,11 +41,14 @@ return nmethod; } - public void print(PrintStream stream) { + public void print(PrintStream stream, boolean printID) { + if (printID) { + stream.print(getId() + " "); + } if (isZombie()) { - stream.printf("%s make_zombie\n", getId()); + stream.println("make_zombie"); } else { - stream.printf("%s make_not_entrant\n", getId()); + stream.println("make_not_entrant"); } } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Method.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Method.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Method.java Tue Mar 10 08:22:36 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,7 @@ private String holder; private String name; private String returnType; - private String arguments; + private String signature; private String bytes; private String iicount; private String flags; @@ -62,6 +62,10 @@ return getHolder().replace('/', '.') + "::" + getName() + " (" + getBytes() + " bytes)"; } + public String getFullName() { + return getHolder().replace('/', '.') + "." + getName() + signature; + } + public String getHolder() { return holder; } @@ -86,15 +90,20 @@ this.returnType = returnType; } - public String getArguments() { - return arguments; + public String getSignature() { + return signature; } - public void setArguments(String arguments) { - this.arguments = arguments; + public void setSignature(String signature) { + this.signature = signature; + } + + public String getArguments() { + return signature.substring(0, signature.indexOf(')') + 1); } public String getBytes() { + if (bytes == null) throw new InternalError(); return bytes; } @@ -117,4 +126,19 @@ public void setFlags(String flags) { this.flags = flags; } + + + public boolean equals(Object other) { + if (!(other instanceof Method)) { + return false; + } + Method otherp = (Method)other; + return otherp.holder.equals(holder) && + otherp.name.equals(name) && + otherp.signature.equals(signature); + } + + public int hashCode() { + return holder.hashCode() ^ name.hashCode(); + } } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/NMethod.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/NMethod.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/NMethod.java Tue Mar 10 08:22:36 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,14 +30,16 @@ private long address; private long size; + private String compiler; - NMethod(double s, String i, long a, long sz) { + NMethod(double s, String i, long a, long sz, String c) { super(s, i); address = a; size = sz; + compiler = c; } - public void print(PrintStream out) { + public void print(PrintStream out, boolean printID) { // XXX Currently we do nothing // throw new InternalError(); } @@ -57,4 +59,8 @@ public void setSize(long size) { this.size = size; } + + public String getCompiler() { + return compiler; + } } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Phase.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Phase.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Phase.java Tue Mar 10 08:22:36 2015 -0700 @@ -57,7 +57,7 @@ } @Override - public void print(PrintStream stream) { + public void print(PrintStream stream, boolean printID) { throw new UnsupportedOperationException("Not supported yet."); } } diff -r df3d4a91f7f6 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java Wed Apr 18 16:08:34 2012 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java Tue Mar 10 08:22:36 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,33 +25,42 @@ package com.sun.hotspot.tools.compiler; import java.io.PrintStream; +import java.util.List; -class UncommonTrapEvent extends BasicLogEvent { - +class UncommonTrapEvent extends JVMSLogEvent { + private final String id; + private final double start; private final String reason; private final String action; + private String bytecode; private int count; - private String jvms = ""; - UncommonTrapEvent(double s, String i, String r, String a, int c) { - super(s, i); + public UncommonTrapEvent(double s, String i, String r, String a, int c) { + super(null); + start = s; + id = i; reason = r; action = a; count = c; } + public double getStart() { + return start; + } - public void addJVMS(String method, int bci) { - setJvms(getJvms() + " @" + bci + " " + method + "\n"); + public String getId() { + return id; } public void updateCount(UncommonTrapEvent trap) { setCount(Math.max(getCount(), trap.getCount())); } - public void print(PrintStream stream) { - stream.printf("%s uncommon trap %s %s\n", getId(), getReason(), getAction()); - stream.print(getJvms()); + public void printPrefix(PrintStream stream, boolean printID) { + if (printID) { + stream.print(getId() + " "); + } + stream.printf("uncommon trap %s %s %s\n", bytecode, getReason(), getAction()); } public String getReason() { @@ -70,15 +79,46 @@ this.count = count; } - public String getJvms() { - return jvms; - } - - public void setJvms(String jvms) { - this.jvms = jvms; - } - public void setCompilation(Compilation compilation) { this.compilation = compilation; + // Attempt to associate a bytecode with with this trap + CallSite site = compilation.getCall(); + int i = 0; + try { + List traps = site.getTraps(); + while (i + 1 < jvmsMethods.length) { + if (!jvmsMethods[i].equals(site.getMethod().getFullName())) { + throw new InternalError(jvmsMethods[i] + " != " + site.getMethod().getFullName()); + } + CallSite result = null; + for (CallSite call : site.getCalls()) { + if (call.getBCI() == jvmsBCIs[i] && + call.getMethod().getFullName().equals(jvmsMethods[i + 1]) && + call.getReceiver() == null) { + result = call; + i++; + break; + } + } + if (result == null) { + throw new InternalError(); + } + site = result; + traps = site.getTraps(); + } + for (UncommonTrap trap : traps) { + if (trap.getBCI() == jvmsBCIs[i] && + trap.getReason().equals(getReason()) && + trap.getAction().equals(getAction())) { + bytecode = trap.getBytecode(); + // System.err.println(bytecode); + return; + } + } + throw new InternalError("couldn't find bytecode"); + } catch (Exception e) { + bytecode = ""; + } + } }