8228674: LogCompilation: Improvements to log compare feature

Show compiler and level in compare output

Reviewed-by: kvn, thartmann
This commit is contained in:
Eric Caspole 2019-07-31 09:55:26 -04:00
parent ab9aab646b
commit c3c35c1b6d
7 changed files with 252 additions and 25 deletions

View File

@ -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 @@ public class CallSite {
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());
}

View File

@ -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 @@ public class Compilation implements LogEvent {
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 @@ public class Compilation implements LogEvent {
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 @@ public class Compilation implements LogEvent {
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 @@ public class Compilation implements LogEvent {
}
}
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 class Compilation implements LogEvent {
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);
}
}
}

View File

@ -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
@ -65,6 +65,11 @@ public class LogCompilation extends DefaultHandler implements ErrorHandler {
System.exit(exitcode);
}
/**
* 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 @@ public class LogCompilation extends DefaultHandler implements ErrorHandler {
boolean cleanup = false;
boolean trapHistory = false;
boolean printTimeStamps = false;
boolean compare = false;
boolean printID = true;
int index = 0;
@ -254,24 +258,29 @@ public class LogCompilation extends DefaultHandler implements ErrorHandler {
* {@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 @@ public class LogCompilation extends DefaultHandler implements ErrorHandler {
if (bci != -1) {
return method + "@" + bci + " (" + compiler + ")";
} else {
return method + " (" + compiler + ")";
return method + " (" + compiler + "(" + level + "))";
}
}
}
@ -322,8 +331,23 @@ public class LogCompilation extends DefaultHandler implements ErrorHandler {
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);

View File

@ -866,11 +866,11 @@ public class LogParser extends DefaultHandler implements ErrorHandler {
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 @@ public class LogParser extends DefaultHandler implements ErrorHandler {
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 @@ public class LogParser extends DefaultHandler implements ErrorHandler {
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 @@ public class LogParser extends DefaultHandler implements ErrorHandler {
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")) {

View File

@ -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
@ -70,6 +70,16 @@ public class Method {
*/
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
@ -186,4 +196,33 @@ public class Method {
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;
}
}

View File

@ -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 @@ public class NMethod extends BasicLogEvent {
*/
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 @@ public class NMethod extends BasicLogEvent {
* @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;
}
}

View File

@ -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);
}
}