diff --git a/.gitignore b/.gitignore index c34d27c8470..668747f8ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ test/nashorn/lib NashornProfile.txt **/JTreport/** **/JTwork/** +/src/utils/LogCompilation/target/ diff --git a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Compilation.java b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Compilation.java index 4fd8c517c65..caf2fe4bbf7 100644 --- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Compilation.java +++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/Compilation.java @@ -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)"); diff --git a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogCompilation.java b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogCompilation.java index e6c00fde72f..d042b860cb6 100644 --- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogCompilation.java +++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogCompilation.java @@ -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++; diff --git a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogParser.java b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogParser.java index 585cda0a91a..5b9c72fafe2 100644 --- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogParser.java +++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/LogParser.java @@ -381,6 +381,55 @@ public class LogParser extends DefaultHandler implements ErrorHandler { } }; + static Comparator sortByNMethodSize = new Comparator() { + + 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); diff --git a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/NMethod.java b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/NMethod.java index b9b5d281dc4..35c56f8776f 100644 --- a/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/NMethod.java +++ b/src/utils/LogCompilation/src/main/java/com/sun/hotspot/tools/compiler/NMethod.java @@ -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 */ diff --git a/src/utils/LogCompilation/src/test/java/com/sun/hotspot/tools/compiler/TestLogCompilation.java b/src/utils/LogCompilation/src/test/java/com/sun/hotspot/tools/compiler/TestLogCompilation.java index 2cb1d0a80cf..83762df16d6 100644 --- a/src/utils/LogCompilation/src/test/java/com/sun/hotspot/tools/compiler/TestLogCompilation.java +++ b/src/utils/LogCompilation/src/test/java/com/sun/hotspot/tools/compiler/TestLogCompilation.java @@ -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); + } }