001/*
002 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.truffle.debug;
024
025import java.util.*;
026
027import jdk.internal.jvmci.code.*;
028
029import com.oracle.graal.nodes.*;
030import com.oracle.graal.truffle.*;
031
032public abstract class AbstractDebugCompilationListener implements GraalTruffleCompilationListener {
033
034    public void notifyCompilationQueued(OptimizedCallTarget target) {
035    }
036
037    public void notifyCompilationDequeued(OptimizedCallTarget target, Object source, CharSequence reason) {
038    }
039
040    public void notifyCompilationFailed(OptimizedCallTarget target, StructuredGraph graph, Throwable t) {
041    }
042
043    public void notifyCompilationStarted(OptimizedCallTarget target) {
044    }
045
046    public void notifyCompilationTruffleTierFinished(OptimizedCallTarget target, StructuredGraph graph) {
047    }
048
049    public void notifyCompilationGraalTierFinished(OptimizedCallTarget target, StructuredGraph graph) {
050    }
051
052    public void notifyCompilationSplit(OptimizedDirectCallNode callNode) {
053    }
054
055    public void notifyCompilationSuccess(OptimizedCallTarget target, StructuredGraph graph, CompilationResult result) {
056    }
057
058    public void notifyCompilationInvalidated(OptimizedCallTarget target, Object source, CharSequence reason) {
059    }
060
061    public void notifyShutdown(GraalTruffleRuntime runtime) {
062    }
063
064    public void notifyStartup(GraalTruffleRuntime runtime) {
065    }
066
067    public static void log(OptimizedCallTarget target, int indent, String msg, String details, Map<String, Object> properties) {
068        int spaceIndent = indent * 2;
069        StringBuilder sb = new StringBuilder();
070        sb.append(String.format("[truffle] %-16s ", msg));
071        for (int i = 0; i < spaceIndent; i++) {
072            sb.append(' ');
073        }
074        sb.append(String.format("%-" + (60 - spaceIndent) + "s", details));
075        if (properties != null) {
076            for (String property : properties.keySet()) {
077                Object value = properties.get(property);
078                if (value == null) {
079                    continue;
080                }
081                sb.append('|');
082                sb.append(property);
083
084                StringBuilder propertyBuilder = new StringBuilder();
085                if (value instanceof Integer) {
086                    propertyBuilder.append(String.format("%6d", value));
087                } else if (value instanceof Double) {
088                    propertyBuilder.append(String.format("%8.2f", value));
089                } else {
090                    propertyBuilder.append(value);
091                }
092
093                int length = Math.max(1, 20 - property.length());
094                sb.append(String.format(" %" + length + "s ", propertyBuilder.toString()));
095            }
096        }
097        target.log(sb.toString());
098    }
099
100    public static void addASTSizeProperty(OptimizedCallTarget target, Map<String, Object> properties) {
101        int nodeCount = target.getNonTrivialNodeCount();
102        int deepNodeCount = nodeCount;
103        TruffleInlining inlining = target.getInlining();
104        if (inlining != null) {
105            deepNodeCount += inlining.getInlinedNodeCount();
106        }
107        properties.put("ASTSize", String.format("%5d/%5d", nodeCount, deepNodeCount));
108
109    }
110
111}