# HG changeset patch # User Tom Rodriguez # Date 1401842918 25200 # Node ID 5f3c8ebf4940e97ba96c26765985791075b5512b # Parent 5c70a97bc5cce99231ac520cb5120e45aae6ae98 fix sorting of output in LogCompilation and add reporting of eliminated locks diff -r 5c70a97bc5cc -r 5f3c8ebf4940 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java Tue Jun 03 17:32:39 2014 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java Tue Jun 03 17:48:38 2014 -0700 @@ -26,6 +26,7 @@ import java.io.PrintStream; import java.util.ArrayList; +import java.util.List; public class Compilation implements LogEvent { @@ -44,6 +45,7 @@ private NMethod nmethod; private ArrayList phases = new ArrayList(4); private String failureReason; + private List eliminatedLocks = new ArrayList(); Compilation(int id) { this.id = id; @@ -77,9 +79,11 @@ sb.append("+"); sb.append(getBcount()); sb.append("\n"); - for (CallSite site : getCall().getCalls()) { - sb.append(site); - sb.append("\n"); + if (getCall().getCalls() != null) { + for (CallSite site : getCall().getCalls()) { + sb.append(site); + sb.append("\n"); + } } if (getLateInlineCall().getCalls() != null) { sb.append("late inline:\n"); @@ -91,15 +95,19 @@ return sb.toString(); } - public void printShort(PrintStream stream) { + public String shortName() { if (getMethod() == null) { - stream.println(getSpecial()); + return getSpecial(); } else { int bc = isOsr() ? getOsr_bci() : -1; - stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); + return getId() + getMethod().decodeFlags(bc) + getMethod().format(bc); } } + public void printShort(PrintStream stream) { + stream.println(shortName()); + } + public void print(PrintStream stream) { print(stream, 0, false); } @@ -255,4 +263,12 @@ public Compilation getCompilation() { return this; } + + public void addEliminatedLock(JVMState jvms) { + eliminatedLocks.add(jvms); + } + + public List getEliminatedLocks() { + return eliminatedLocks; + } } diff -r 5c70a97bc5cc -r 5f3c8ebf4940 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/JVMState.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/JVMState.java Tue Jun 03 17:48:38 2014 -0700 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014, 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; + +public class JVMState { + final Method method; + final int bci; + JVMState outer; + + JVMState(Method method, int bci) { + this.method = method; + this.bci = bci; + } + + void push(JVMState jvms) { + if (outer == null) { + outer = jvms; + } else { + outer.push(jvms); + } + } +} diff -r 5c70a97bc5cc -r 5f3c8ebf4940 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java Tue Jun 03 17:32:39 2014 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogCompilation.java Tue Jun 03 17:48:38 2014 -0700 @@ -44,6 +44,7 @@ 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"); + System.out.println(" -L: print eliminated locks"); System.exit(exitcode); } @@ -52,6 +53,7 @@ boolean statistics = false; boolean printInlining = false; boolean cleanup = false; + boolean printEliminatedLocks = false; int index = 0; while (args.length > index) { @@ -75,6 +77,9 @@ } else if (args[index].equals("-i")) { printInlining = true; index++; + } else if (args[index].equals("-L")) { + printEliminatedLocks = true; + index++; } else { break; } @@ -87,11 +92,34 @@ while (index < args.length) { ArrayList events = LogParser.parse(args[index], cleanup); - if (statistics) { + if (printEliminatedLocks) { + Collections.sort(events, defaultSort); + for (LogEvent e : events) { + if (e instanceof Compilation) { + Compilation c = (Compilation) e; + List eliminated = c.getEliminatedLocks(); + if (!eliminated.isEmpty()) { + c.print(System.out); + System.out.println(" Eliminated locks"); + for (JVMState jvms : eliminated) { + System.err.print(" "); + while (jvms != null) { + System.out.printf(" %s.%s@%d", jvms.method.getHolder().replace('/', '.'), jvms.method.getName(), jvms.bci); + jvms = jvms.outer; + } + System.out.println(); + } + } + } + } + } else if (statistics) { printStatistics(events, System.out); } else { Collections.sort(events, defaultSort); for (LogEvent c : events) { + if (c instanceof NMethod) continue; + + System.out.printf("%f ", c.getStart()); if (printInlining && c instanceof Compilation) { Compilation comp = (Compilation)c; comp.print(System.out, true); @@ -141,7 +169,7 @@ nodes created in the phase, live nodes at the start of the phase, live nodes added in the phase. */ - out.printf("\t%s %6.4f %d %d %d %d\n", phase.getName(), phase.getElapsedTime(), phase.getStartNodes(), phase.getNodes(), phase.getStartLiveNodes(), phase.getLiveNodes()); + // out.printf("\t%s %6.4f %d %d %d %d\n", phase.getName(), phase.getElapsedTime(), phase.getStartNodes(), phase.getNodes(), phase.getStartLiveNodes(), phase.getLiveNodes()); } } else if (e instanceof MakeNotEntrantEvent) { MakeNotEntrantEvent mne = (MakeNotEntrantEvent) e; diff -r 5c70a97bc5cc -r 5f3c8ebf4940 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java Tue Jun 03 17:32:39 2014 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/LogParser.java Tue Jun 03 17:48:38 2014 -0700 @@ -89,15 +89,12 @@ if (result != 0) { return result; } - } - double difference = (a.getStart() - b.getStart()); - if (difference < 0) { + } else if (c1 == null && c2 != null) { return -1; - } - if (difference > 0) { + } else if (c2 == null && c1 != null) { return 1; } - return 0; + return Double.compare(a.getStart(), b.getStart()); } public boolean equals(Object other) { @@ -138,6 +135,7 @@ private HashMap types = new HashMap(); private HashMap methods = new HashMap(); private LinkedHashMap nmethods = new LinkedHashMap(); + private ArrayList notEntrantEvents = new ArrayList(); private HashMap compiles = new HashMap(); private String failureReason; private int bci; @@ -147,6 +145,8 @@ private Stack phaseStack = new Stack(); private UncommonTrapEvent currentTrap; private Stack late_inline_scope; + private JVMState eliminated_lock; + private boolean in_eliminate_lock; long parseLong(String l) { try { @@ -191,15 +191,34 @@ p.parse(new InputSource(reader), log); // Associate compilations with their NMethods - for (NMethod nm : log.nmethods.values()) { - Compilation c = log.compiles.get(nm.getId()); - nm.setCompilation(c); - // Native wrappers for methods don't have a compilation - if (c != null) { - c.setNMethod(nm); + for (LogEvent le : log.events) { + if (le instanceof BasicLogEvent) { + BasicLogEvent ble = (BasicLogEvent) le; + Compilation c = log.compiles.get(ble.getId()); + ble.setCompilation(c); + if (ble instanceof NMethod) { + NMethod nm = (NMethod) ble; + // Native wrappers for methods don't have a compilation and Graal methods don't either. + if (c != null) { + c.setNMethod(nm); + } + } else { + if (c == null) { + throw new InternalError("can't find compilation " + ble.getId() + " for " + ble); + } + } } } + + for (MakeNotEntrantEvent ne : log.notEntrantEvents) { + Compilation c = log.compiles.get(ne.getId()); + if (c == null) { + throw new InternalError("can't find compilation " + ne.getId()); + } + ne.setCompilation(c); + } + // Initially we want the LogEvent log sorted by timestamp Collections.sort(log.events, sortByStart); @@ -353,8 +372,9 @@ String id = makeId(atts); NMethod nm = nmethods.get(id); if (nm == null) throw new InternalError(); - LogEvent e = new MakeNotEntrantEvent(Double.parseDouble(search(atts, "stamp")), id, - atts.getValue("zombie") != null, nm); + MakeNotEntrantEvent e = new MakeNotEntrantEvent(Double.parseDouble(search(atts, "stamp")), id, + atts.getValue("zombie") != null, nm); + notEntrantEvents.add(e); events.add(e); } else if (qname.equals("uncommon_trap")) { String id = atts.getValue("compile_id"); @@ -374,6 +394,8 @@ late_inline_scope = new Stack(); site = new CallSite(-999, method(search(atts, "method"))); late_inline_scope.push(site); + } else if (qname.equals("eliminate_lock")) { + in_eliminate_lock = true; } else if (qname.equals("jvms")) { // if (currentTrap != null) { @@ -382,6 +404,13 @@ bci = Integer.parseInt(search(atts, "bci")); site = new CallSite(bci, method(search(atts, "method"))); late_inline_scope.push(site); + } else if (in_eliminate_lock) { + JVMState jvms = new JVMState(method(atts.getValue("method")), Integer.parseInt(atts.getValue("bci"))); + if (eliminated_lock == null) { + eliminated_lock = jvms; + } else { + eliminated_lock.push(jvms); + } } else { // Ignore , // , @@ -390,9 +419,10 @@ } else if (qname.equals("nmethod")) { String id = makeId(atts); NMethod nm = new NMethod(Double.parseDouble(search(atts, "stamp")), - id, - parseLong(atts.getValue("address")), - parseLong(atts.getValue("size"))); + id, + atts.getValue("compile_kind"), + parseLong(atts.getValue("address")), + parseLong(atts.getValue("size"))); nmethods.put(id, nm); events.add(nm); } else if (qname.equals("parse")) { @@ -429,6 +459,13 @@ scopes.pop(); } else if (qname.equals("uncommon_trap")) { currentTrap = null; + } else if (qname.equals("eliminate_lock")) { + if (eliminated_lock != null) { + // There's no JVM state on the unlock, so ignore it + compile.addEliminatedLock(eliminated_lock); + } + eliminated_lock = null; + in_eliminate_lock = false; } else if (qname.equals("late_inline")) { // Populate late inlining info. diff -r 5c70a97bc5cc -r 5f3c8ebf4940 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/MakeNotEntrantEvent.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/MakeNotEntrantEvent.java Tue Jun 03 17:32:39 2014 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/MakeNotEntrantEvent.java Tue Jun 03 17:48:38 2014 -0700 @@ -43,9 +43,9 @@ public void print(PrintStream stream) { if (isZombie()) { - stream.printf("%s make_zombie\n", getId()); + stream.printf("%s make_zombie\n", compilation.shortName()); } else { - stream.printf("%s make_not_entrant\n", getId()); + stream.printf("%s make_not_entrant\n", compilation.shortName()); } } diff -r 5c70a97bc5cc -r 5f3c8ebf4940 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/NMethod.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/NMethod.java Tue Jun 03 17:32:39 2014 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/NMethod.java Tue Jun 03 17:48:38 2014 -0700 @@ -30,11 +30,17 @@ private long address; private long size; + private String compileKind; - NMethod(double s, String i, long a, long sz) { + NMethod(double s, String i, String k, long a, long sz) { super(s, i); address = a; size = sz; + if (k == null) { + compileKind = "normal"; + } else { + compileKind = k; + } } public void print(PrintStream out) { @@ -50,6 +56,10 @@ this.address = address; } + public String getKind() { + return compileKind; + } + public long getSize() { return size; } diff -r 5c70a97bc5cc -r 5f3c8ebf4940 src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java --- a/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java Tue Jun 03 17:32:39 2014 -0700 +++ b/src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/UncommonTrapEvent.java Tue Jun 03 17:48:38 2014 -0700 @@ -40,7 +40,6 @@ count = c; } - public void addJVMS(String method, int bci) { setJvms(getJvms() + " @" + bci + " " + method + "\n"); } @@ -50,7 +49,7 @@ } public void print(PrintStream stream) { - stream.printf("%s uncommon trap %s %s\n", getId(), getReason(), getAction()); + stream.printf("%s uncommon trap %s %s\n", compilation.shortName(), getReason(), getAction()); stream.print(getJvms()); } @@ -77,8 +76,4 @@ public void setJvms(String jvms) { this.jvms = jvms; } - - public void setCompilation(Compilation compilation) { - this.compilation = compilation; - } }