changeset 22706:5cae0a06ca7d

Add trap and recompilation statistics to LogCompilation
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Fri, 23 Oct 2015 10:10:17 -0700
parents 76e1d16c28cc
children 829a9e1ccf23
files src/share/tools/LogCompilation/Makefile src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Method.java src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java
diffstat 5 files changed, 80 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/tools/LogCompilation/Makefile	Fri Oct 23 10:09:48 2015 -0700
+++ b/src/share/tools/LogCompilation/Makefile	Fri Oct 23 10:10:17 2015 -0700
@@ -62,7 +62,7 @@
 
 logc.jar: filelist manifest.mf
 	@mkdir -p $(OUTPUT_DIR)
-	$(JAVAC) -source 1.5 -deprecation -sourcepath $(SRC_DIR) -d $(OUTPUT_DIR) @filelist
+	$(JAVAC) -source 1.6 -deprecation -sourcepath $(SRC_DIR) -d $(OUTPUT_DIR) @filelist
 	$(JAR) cvfm logc.jar manifest.mf -C $(OUTPUT_DIR) com
 
 .PHONY: filelist
--- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java	Fri Oct 23 10:09:48 2015 -0700
+++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java	Fri Oct 23 10:10:17 2015 -0700
@@ -104,6 +104,15 @@
         }
     }
 
+    public String longMethodName() {
+        if (getMethod() == null) {
+            return getSpecial();
+        } else {
+            int bc = isOsr() ? getOsr_bci() : -1;
+            return getMethod().decodeFlags(bc) + getMethod().formatLong(bc);
+        }
+    }
+
     public void printShort(PrintStream stream) {
         stream.println(shortName());
     }
--- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java	Fri Oct 23 10:09:48 2015 -0700
+++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java	Fri Oct 23 10:10:17 2015 -0700
@@ -41,6 +41,7 @@
         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("  -R:   print method recompilation information");
         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");
@@ -52,6 +53,7 @@
     public static void main(String[] args) throws Exception {
         Comparator<LogEvent> defaultSort = LogParser.sortByStart;
         boolean statistics = false;
+        boolean recompilation = false;
         boolean printInlining = false;
         boolean cleanup = false;
         boolean printEliminatedLocks = false;
@@ -74,6 +76,9 @@
             } else if (args[index].equals("-S")) {
                 statistics = true;
                 index++;
+            } else if (args[index].equals("-R")) {
+                recompilation = true;
+                index++;
             } else if (args[index].equals("-h")) {
                 usage(0);
             } else if (args[index].equals("-i")) {
@@ -103,6 +108,8 @@
                 printEliminatedLocks(events, System.out, defaultSort);
             } else if (statistics) {
                 printStatistics(events, System.out);
+            } else if (recompilation) {
+                printRecompilation(events, System.out);
             } else {
                 Collections.sort(events, defaultSort);
                 for (LogEvent c : events) {
@@ -196,6 +203,54 @@
         }
     }
     
+    public static void printRecompilation(ArrayList<LogEvent> events, PrintStream out) {
+        LinkedHashMap<String, Map<String, List<String>>> traps = new LinkedHashMap<String, Map<String, List<String>>>();
+        for (LogEvent e : events) {
+            if (e instanceof UncommonTrapEvent) {
+                UncommonTrapEvent uc = (UncommonTrapEvent) e;
+                Map<String, List<String>> t = traps.get(uc.getCompilation().longMethodName());
+                if (t == null) {
+                    t = new LinkedHashMap<String, List<String>>();
+                    traps.put(uc.getCompilation().longMethodName(), t);
+                }
+                String msg = uc.formatTrap().trim();
+                List<String> i = t.get(msg);
+                if (i == null) {
+                    i = new ArrayList<String>();
+                    t.put(msg, i);
+                }
+                i.add(uc.getId());
+            }
+        }
+
+        List<List<String>> recompiles = new ArrayList<List<String>>();
+        Map<List<String>, String> reverseMapping = new HashMap<List<String>, String>();
+        for (Map.Entry<String, Map<String, List<String>>> entry : traps.entrySet()) {
+            for (Map.Entry<String, List<String>> trapEntry : entry.getValue().entrySet()) {
+                recompiles.add(trapEntry.getValue());
+                reverseMapping.put(trapEntry.getValue(), trapEntry.getKey());
+            }
+        }
+        recompiles.sort(new Comparator<List<String>>() {
+            public int compare(List<String> a, List<String> b) {
+                return intCompare(a.size(), b.size());
+            }
+        });
+        for (List<String> key : recompiles) {
+            if (key.size() > 1) {
+                out.print("Trap: ");
+                out.println(reverseMapping.get(key));
+                out.print("Compilations: ");
+                out.println(key);
+            }
+        }
+    }
+    
+
+    private static int intCompare(int o1, int o2) {
+        return (o1 > o2 ? -1 : (o1 == o2 ? 0 : 1));
+    }
+
     public static void printStatistics(ArrayList<LogEvent> events, PrintStream out) {
         long cacheSize = 0;
         long maxCacheSize = 0;
--- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Method.java	Fri Oct 23 10:09:48 2015 -0700
+++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Method.java	Fri Oct 23 10:10:17 2015 -0700
@@ -50,11 +50,19 @@
     }
 
     String format(int osr_bci) {
+        String bci = "";
         if (osr_bci >= 0) {
-            return getHolder().replace('/', '.') + "::" + getName() + " @ " + osr_bci + " (" + getBytes() + " bytes)";
-        } else {
-            return getHolder().replace('/', '.') + "::" + getName() + " (" + getBytes() + " bytes)";
+            bci = " @ " + osr_bci;
         }
+        return getHolder().replace('/', '.') + "::" + getName() + bci + " (" + getBytes() + " bytes)";
+    }
+
+    String formatLong(int osr_bci) {
+        String bci = "";
+        if (osr_bci >= 0) {
+            bci = " @ " + osr_bci;
+        }
+        return getReturnType() + " " + getHolder().replace('/', '.') + "::" + getName() + "(" + getArguments() + ")" + bci;
     }
 
     @Override
--- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java	Fri Oct 23 10:09:48 2015 -0700
+++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java	Fri Oct 23 10:10:17 2015 -0700
@@ -53,6 +53,10 @@
         stream.print(getJvms());
     }
 
+    public String formatTrap() {
+        return String.format("uncommon trap %s %s\n%s", getReason(), getAction(), getJvms());
+    }
+
     public String getReason() {
         return reason;
     }