8228674: LogCompilation: Improvements to log compare feature
authorecaspole
Wed, 31 Jul 2019 09:55:26 -0400
changeset 57605 694565998531
parent 57603 f9d9bed12d1a
child 57606 b81062d47d61
8228674: LogCompilation: Improvements to log compare feature Summary: Show compiler and level in compare output Reviewed-by: kvn, thartmann
src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/CallSite.java
src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Compilation.java
src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogCompilation.java
src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogParser.java
src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Method.java
src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/NMethod.java
src/utils/LogCompilation/src/test/java/com/sun/hotspot/tools/compiler/TestCompare.java
--- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/CallSite.java	Wed Jul 31 06:54:50 2019 -0400
+++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/CallSite.java	Wed Jul 31 09:55:26 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, 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
@@ -185,7 +185,10 @@
             stream.print("  @ " + getBci() + " " + m + " " + getReason());
         }
         stream.print(getIntrinsicOrEmptyString());
-        stream.printf(" (end time: %6.4f", getTimeStamp());
+        if (LogCompilation.compare == false) {
+            // The timestamp is not useful for log comparison
+            stream.printf(" (end time: %6.4f", getTimeStamp());
+        }
         if (getEndNodes() > 0) {
             stream.printf(" nodes: %d live: %d", getEndNodes(), getEndLiveNodes());
         }
--- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Compilation.java	Wed Jul 31 06:54:50 2019 -0400
+++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Compilation.java	Wed Jul 31 09:55:26 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, 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
@@ -83,9 +83,9 @@
     private String special;
 
     /**
-     * The name of the compiler performing this compilation.
+     * The compilation level for this task.
      */
-    private String compiler;
+    private long level;
 
     /**
      * Start time stamp.
@@ -152,12 +152,12 @@
         return start;
     }
 
-    public void setCompiler(String compiler) {
-        this.compiler = compiler;
-    }
-
     public String getCompiler() {
-        return compiler;
+        assert getNMethod() != null  || getFailureReason() != null : "Null nmethod for Compilation:" + getId() + " " + getMethod();
+        if (getNMethod() != null) {
+            getNMethod().getCompiler();
+        }
+        return "";
     }
 
     @Override
@@ -194,7 +194,7 @@
             stream.println(getSpecial());
         } else {
             int bc = isOsr() ? getBCI() : -1;
-            stream.print(getId() + getMethod().decodeFlags(bc) + " " + compiler + " " + getMethod().format(bc));
+            stream.print(getId() + getMethod().decodeFlags(bc) + " " + getCompiler() + " " + getMethod().format(bc));
         }
     }
 
@@ -222,7 +222,7 @@
                 }
             }
             int bc = isOsr() ? getBCI() : -1;
-            stream.print(getMethod().decodeFlags(bc) + " " + compiler + " " + getMethod().format(bc));
+            stream.print(getMethod().decodeFlags(bc) + " " + getCompiler() + " " + getMethod().format(bc));
             stream.println();
             if (getFailureReason() != null) {
                 stream.println("COMPILE SKIPPED: " + getFailureReason() + " (not retryable)");
@@ -365,4 +365,21 @@
     public Compilation getCompilation() {
         return this;
     }
+
+    /**
+     * @return the level
+     */
+    public long getLevel() {
+        return level;
+    }
+
+    /**
+     * @param level the level to set
+     */
+    public void setLevel(long level) {
+        this.level = level;
+        if (getMethod() != null) {
+            getMethod().setLevel(level);
+        }
+    }
 }
--- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogCompilation.java	Wed Jul 31 06:54:50 2019 -0400
+++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogCompilation.java	Wed Jul 31 09:55:26 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, 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
@@ -66,6 +66,11 @@
     }
 
     /**
+     * compare controls how some output is formatted
+     */
+    public static boolean compare = false;
+
+    /**
      * Process command line arguments, parse log files and trigger desired
      * functionality.
      */
@@ -76,7 +81,6 @@
         boolean cleanup = false;
         boolean trapHistory = false;
         boolean printTimeStamps = false;
-        boolean compare = false;
         boolean printID = true;
         int index = 0;
 
@@ -254,24 +258,29 @@
      * {@linkplain #compareLogs() comparing logs}.
      */
     static class MethodBCIPair {
-        public MethodBCIPair(Method m, int b, String c) {
+        public MethodBCIPair(Method m, int b, String c, long l) {
             method = m;
             bci = b;
             compiler = c;
+            level = l;
         }
 
         Method method;
         int bci;
         String compiler;
+        long level;
 
         public boolean equals(Object other) {
             if (!(other instanceof MethodBCIPair)) {
                 return false;
             }
             MethodBCIPair otherp = (MethodBCIPair)other;
+            assert otherp.compiler != null : "otherp null compiler: " + otherp;
+            assert method.getCompiler() != compiler : "Compiler doesnt match";
             return (otherp.bci == bci &&
                     otherp.method.equals(method) &&
-                    otherp.compiler.equals(compiler));
+                    otherp.compiler.equals(compiler) &&
+                    otherp.level == level);
         }
 
         public int hashCode() {
@@ -282,7 +291,7 @@
             if (bci != -1) {
                 return method + "@" + bci + " (" + compiler + ")";
             } else {
-                return method + " (" + compiler + ")";
+                return method + " (" + compiler + "(" + level + "))";
             }
         }
     }
@@ -322,8 +331,23 @@
             for (LogEvent c : events) {
                 if (c instanceof Compilation) {
                     Compilation comp = (Compilation) c;
-                    MethodBCIPair key = new MethodBCIPair(comp.getMethod(), comp.getBCI(),
-                                                          comp.getCompiler());
+                    assert (comp.getNMethod() != null  || comp.getFailureReason() != null ): "NMethod is null in compare: " + comp;
+                    String compiler = comp.getNMethod() != null ? comp.getNMethod().getCompiler() :
+                            (comp.getCompiler() != null ? comp.getCompiler() : "");
+                    assert compiler != null : "Compiler is null in compare: " + comp;
+                    long level = -99;
+                    if (comp.getLevel() == 0) {
+                        if (comp.getNMethod() != null) {
+                            level = comp.getNMethod().getLevel();
+                        }
+                        if (level == 0) {
+                            level = comp.getMethod().getLevel();
+                        }
+                    } else {
+                        level = comp.getLevel();
+                    }
+                    assert level != -99 || comp.getFailureReason() != null : "Failed Compile";
+                    MethodBCIPair key = new MethodBCIPair(comp.getMethod(), comp.getBCI(), compiler, level);
                     MethodBCIPair e = methods.get(key);
                     if (e == null) {
                         methods.put(key, key);
--- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogParser.java	Wed Jul 31 06:54:50 2019 -0400
+++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogParser.java	Wed Jul 31 09:55:26 2019 -0400
@@ -866,11 +866,11 @@
             compile.setBCount(search(atts, "backedge_count", "0"));
             compile.setBCI(Integer.parseInt(search(atts, "osr_bci", "-1")));
             String compiler = atts.getValue("compiler");
-            if (compiler == null) {
-                compiler = "";
+            assert compiler == null : "Compiler is not specified in task";
+            long level = parseLong(search(atts, "level", "0"));
+            if (level != 0) {
+                compile.setLevel(level);
             }
-            compile.setCompiler(compiler);
-
             // Extract the name of the compiled method.
             String[] parts = spacePattern.split(atts.getValue("method"));
             String methodName = parts[0] + "::" + parts[1];
@@ -896,6 +896,7 @@
             m.setSignature(parts[2]);
             m.setFlags("0");
             m.setBytes(search(atts, "bytes", "unknown"));
+            m.setLevel(compile.getLevel());
             compile.setMethod(m);
             events.add(compile);
             compiles.put(id, compile);
@@ -932,6 +933,12 @@
                m.setIICount(search(atts, "iicount"));
                m.setFlags(search(atts, "flags"));
             }
+            String compiler = search(atts, "compiler", "");
+            m.setCompiler(compiler);
+            long level = parseLong(search(atts, "level", "0"));
+            if (level != 0) {
+                m.setLevel(level);
+            }
             methods.put(id, m);
         } else if (qname.equals("call")) {
             if (methodHandleSite != null) {
@@ -1100,6 +1107,8 @@
             if (level != null) {
                 nm.setLevel(parseLong(level));
             }
+            String compiler = search(atts, "compiler", "");
+            nm.setCompiler(compiler);
             nmethods.put(id, nm);
             events.add(nm);
         } else if (qname.equals("parse")) {
--- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Method.java	Wed Jul 31 06:54:50 2019 -0400
+++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Method.java	Wed Jul 31 09:55:26 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, 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,6 +71,16 @@
     private String flags;
 
     /**
+     * The name of the compiler performing this compilation.
+     */
+    private String compiler;
+
+    /**
+     * The nmethod's compilation level.
+     */
+    private long level;
+
+    /**
      * Decode the {@link flags} numerical string to a format for console
      * output. The result does not honour all possible flags but includes
      * information about OSR compilation.
@@ -186,4 +196,33 @@
     public int hashCode() {
         return holder.hashCode() ^ name.hashCode();
     }
+
+    /**
+     * @return the compiler
+     */
+    public String getCompiler() {
+        return compiler;
+    }
+
+    /**
+     * @param compiler the compiler to set
+     */
+    public void setCompiler(String compiler) {
+        this.compiler = compiler;
+    }
+
+    /**
+     * @return the level
+     */
+    public long getLevel() {
+        return level;
+    }
+
+    /**
+     * @param level the level to set
+     */
+    public void setLevel(long level) {
+        assert this.level == 0 || this.level == level;
+        this.level = level;
+    }
 }
--- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/NMethod.java	Wed Jul 31 06:54:50 2019 -0400
+++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/NMethod.java	Wed Jul 31 09:55:26 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2019, 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
@@ -47,6 +47,11 @@
      */
     private long level;
 
+    /**
+     * The name of the compiler performing this compilation.
+     */
+    private String compiler;
+
     NMethod(double s, String i, long a, long sz) {
         super(s, i);
         address = a;
@@ -85,6 +90,21 @@
      * @param level the level to set
      */
     public void setLevel(long level) {
+        assert this.level == 0 || this.level == level;
         this.level = level;
     }
+
+    /**
+     * @return the compiler
+     */
+    public String getCompiler() {
+        return compiler;
+    }
+
+    /**
+     * @param compiler the compiler to set
+     */
+    public void setCompiler(String compiler) {
+        this.compiler = compiler;
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/utils/LogCompilation/src/test/java/com/sun/hotspot/tools/compiler/TestCompare.java	Wed Jul 31 09:55:26 2019 -0400
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2019, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+package com.sun.hotspot.tools.compiler;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(value = Parameterized.class)
+public class TestCompare {
+
+    String logFile;
+
+    static final String setupArgsTieredVersion[] = {
+        "java",
+        "-XX:+UnlockDiagnosticVMOptions",
+        "-XX:+LogCompilation",
+        "-XX:LogFile=target/tiered_version.log",
+        "-version"
+    };
+
+    static final String setupArgsTieredVersion2[] = {
+        "java",
+        "-XX:+UnlockDiagnosticVMOptions",
+        "-XX:+LogCompilation",
+        "-XX:LogFile=target/tiered_version.log.2",
+        "-version"
+    };
+
+        static final String setupArgsNoTiered[] = {
+        "java",
+        "-XX:-TieredCompilation",
+        "-XX:+UnlockDiagnosticVMOptions",
+        "-XX:+LogCompilation",
+        "-XX:LogFile=target/no_tiered_short.log"
+    };
+
+    static final String setupArgsNoTiered2[] = {
+        "java",
+        "-XX:-TieredCompilation",
+        "-XX:+UnlockDiagnosticVMOptions",
+        "-XX:+LogCompilation",
+        "-XX:LogFile=target/no_tiered_short.log.2"
+    };
+
+    static final String allSetupArgs[][] = {
+        setupArgsTieredVersion,
+        setupArgsTieredVersion2,
+        setupArgsNoTiered,
+        setupArgsNoTiered2
+    };
+
+    @Parameters
+    public static Collection data() {
+        Object[][] data = new Object[][]{
+            // Take care these match whats created in the setup method
+            {"./target/tiered_version.log"},
+            {"./target/no_tiered_short.log"}
+        };
+        assert data.length == (allSetupArgs.length/2) : "Files dont match args. Need 2 inputs per test case.";
+        return Arrays.asList(data);
+    }
+
+    @BeforeClass
+    public static void setup() {
+        try {
+            for (String[] setupArgs : allSetupArgs) {
+                Process p = Runtime.getRuntime().exec(setupArgs);
+                p.waitFor();
+            }
+        } catch (Exception e) {
+            System.out.println(e + ": exec failed:" + setupArgsNoTiered[0]);
+        }
+    }
+
+    public TestCompare(String logFile) {
+        this.logFile = logFile;
+    }
+
+    @Test
+    public void testDashC() throws Exception {
+        String[] args = {"-C",
+            logFile,
+            logFile + ".2"
+        };
+
+        LogCompilation.main(args);
+    }
+
+}