8255965: LogCompilation: add sort by nmethod code size

Reviewed-by: kvn, redestad
This commit is contained in:
Eric Caspole 2020-11-05 23:51:27 +00:00
parent e42c134038
commit 57b98fa55a
6 changed files with 96 additions and 5 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ test/nashorn/lib
NashornProfile.txt
**/JTreport/**
**/JTwork/**
/src/utils/LogCompilation/target/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2020, 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
@ -221,8 +221,17 @@ public class Compilation implements LogEvent {
stream.print(" " + nmethod.getLevel());
}
}
String codeSize = "";
if (nmethod != null) {
long nmethodSize = nmethod.getInstSize();
if (nmethodSize > 0) {
codeSize = "(code size: " + nmethodSize + ")";
}
}
int bc = isOsr() ? getBCI() : -1;
stream.print(getMethod().decodeFlags(bc) + " " + getCompiler() + " " + getMethod().format(bc));
stream.print(getMethod().decodeFlags(bc) + " " + getCompiler() + " " + getMethod().format(bc) + codeSize);
stream.println();
if (getFailureReason() != null) {
stream.println("COMPILE SKIPPED: " + getFailureReason() + " (not retryable)");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2020, 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
@ -95,6 +95,9 @@ public class LogCompilation extends DefaultHandler implements ErrorHandler {
} else if (a.equals("-s")) {
sort = LogParser.sortByStart;
index++;
} else if (a.equals("-z")) {
sort = LogParser.sortByNMethodSize;
index++;
} else if (a.equals("-t")) {
printTimeStamps = true;
index++;

View File

@ -381,6 +381,55 @@ public class LogParser extends DefaultHandler implements ErrorHandler {
}
};
static Comparator<LogEvent> sortByNMethodSize = new Comparator<LogEvent>() {
public int compare(LogEvent a, LogEvent b) {
Compilation c1 = a.getCompilation();
Compilation c2 = b.getCompilation();
if ((c1 != null && c2 == null)) {
return -1;
} else if (c1 == null && c2 != null) {
return 1;
} else if (c1 == null && c2 == null) {
return 0;
}
if (c1.getNMethod() != null && c2.getNMethod() == null) {
return -1;
} else if (c1.getNMethod() == null && c2.getNMethod() != null) {
return 1;
} else if (c1.getNMethod() == null && c2.getNMethod() == null) {
return 0;
}
assert c1.getNMethod() != null && c2.getNMethod() != null : "Neither should be null here";
long c1Size = c1.getNMethod().getInstSize();
long c2Size = c2.getNMethod().getInstSize();
if (c1Size == 0 && c2Size == 0) {
return 0;
}
if (c1Size > c2Size) {
return -1;
} else if (c1Size < c2Size) {
return 1;
}
return 0;
}
public boolean equals(Object other) {
return false;
}
@Override
public int hashCode() {
return 7;
}
};
/**
* Shrink-wrapped representation of a JVMState (tailored to meet this
* tool's needs). It only records a method and bytecode instruction index.
@ -1119,6 +1168,13 @@ public class LogParser extends DefaultHandler implements ErrorHandler {
if (level != null) {
nm.setLevel(parseLong(level));
}
String iOffset = atts.getValue("insts_offset");
String sOffset = atts.getValue("stub_offset");
if (iOffset != null && sOffset != null) {
long insts_offset = parseLong(iOffset);
long stub_offset = parseLong(sOffset);
nm.setInstSize(stub_offset - insts_offset);
}
String compiler = search(atts, "compiler", "");
nm.setCompiler(compiler);
nmethods.put(id, nm);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2020, 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
@ -42,6 +42,11 @@ public class NMethod extends BasicLogEvent {
*/
private long size;
/**
* The nmethod's insts size in bytes.
*/
private long instSize;
/**
* The nmethod's compilation level.
*/
@ -79,6 +84,14 @@ public class NMethod extends BasicLogEvent {
this.size = size;
}
public long getInstSize() {
return instSize;
}
public void setInstSize(long size) {
this.instSize = size;
}
/**
* @return the level
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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
@ -177,4 +177,13 @@ public class TestLogCompilation {
LogCompilation.main(args);
}
@Test
public void testDashz() throws Exception {
String[] args = {"-z",
logFile
};
LogCompilation.main(args);
}
}