Compilation.java revision 1472:c18cbe5936b8
1/*
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25package com.sun.hotspot.tools.compiler;
26
27import java.io.PrintStream;
28import java.util.ArrayList;
29
30public class Compilation implements LogEvent {
31
32    private int id;
33    private boolean osr;
34    private Method method;
35    private CallSite call = new CallSite();
36    private int osrBci;
37    private String icount;
38    private String bcount;
39    private String special;
40    private double start;
41    private double end;
42    private int attempts;
43    private NMethod nmethod;
44    private ArrayList<Phase> phases = new ArrayList<Phase>(4);
45    private String failureReason;
46
47    Compilation(int id) {
48        this.id = id;
49    }
50
51    Phase getPhase(String s) {
52        for (Phase p : getPhases()) {
53            if (p.getName().equals(s)) {
54                return p;
55            }
56        }
57        return null;
58    }
59
60    double getRegallocTime() {
61        return getPhase("regalloc").getElapsedTime();
62    }
63
64    public double getStart() {
65        return start;
66    }
67
68    @Override
69    public String toString() {
70        StringBuilder sb = new StringBuilder();
71        sb.append(getId());
72        sb.append(" ");
73        sb.append(getMethod());
74        sb.append(" ");
75        sb.append(getIcount());
76        sb.append("+");
77        sb.append(getBcount());
78        sb.append("\n");
79        for (CallSite site : getCall().getCalls()) {
80            sb.append(site);
81            sb.append("\n");
82        }
83        return sb.toString();
84    }
85
86    public void printShort(PrintStream stream) {
87        if (getMethod() == null) {
88            stream.println(getSpecial());
89        } else {
90            int bc = isOsr() ? getOsr_bci() : -1;
91            stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc));
92        }
93    }
94
95    public void print(PrintStream stream) {
96        print(stream, 0, false);
97    }
98
99    public void print(PrintStream stream, boolean printInlining) {
100        print(stream, 0, printInlining);
101    }
102
103    public void print(PrintStream stream, int indent, boolean printInlining) {
104        if (getMethod() == null) {
105            stream.println(getSpecial());
106        } else {
107            int bc = isOsr() ? getOsr_bci() : -1;
108            stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc));
109            stream.println();
110            if (getFailureReason() != null) {
111                stream.println("COMPILE FAILED " + getFailureReason());
112            }
113            if (printInlining && call.getCalls() != null) {
114                for (CallSite site : call.getCalls()) {
115                    site.print(stream, indent + 2);
116                }
117            }
118        }
119    }
120
121    public int getId() {
122        return id;
123    }
124
125    public void setId(int id) {
126        this.id = id;
127    }
128
129    public boolean isOsr() {
130        return osr;
131    }
132
133    public void setOsr(boolean osr) {
134        this.osr = osr;
135    }
136
137    public int getOsr_bci() {
138        return osrBci;
139    }
140
141    public void setOsr_bci(int osrBci) {
142        this.osrBci = osrBci;
143    }
144
145    public String getIcount() {
146        return icount;
147    }
148
149    public void setICount(String icount) {
150        this.icount = icount;
151    }
152
153    public String getBcount() {
154        return bcount;
155    }
156
157    public void setBCount(String bcount) {
158        this.bcount = bcount;
159    }
160
161    public String getSpecial() {
162        return special;
163    }
164
165    public void setSpecial(String special) {
166        this.special = special;
167    }
168
169    public void setStart(double start) {
170        this.start = start;
171    }
172
173    public double getEnd() {
174        return end;
175    }
176
177    public void setEnd(double end) {
178        this.end = end;
179    }
180
181    public int getAttempts() {
182        return attempts;
183    }
184
185    public void setAttempts(int attempts) {
186        this.attempts = attempts;
187    }
188
189    public NMethod getNMethod() {
190        return nmethod;
191    }
192
193    public void setNMethod(NMethod NMethod) {
194        this.nmethod = NMethod;
195    }
196
197    public ArrayList<Phase> getPhases() {
198        return phases;
199    }
200
201    public void setPhases(ArrayList<Phase> phases) {
202        this.setPhases(phases);
203    }
204
205    public String getFailureReason() {
206        return failureReason;
207    }
208
209    public void setFailureReason(String failureReason) {
210        this.failureReason = failureReason;
211    }
212
213    public Method getMethod() {
214        return method;
215    }
216
217    public void setMethod(Method method) {
218        this.method = method;
219    }
220
221    public CallSite getCall() {
222        return call;
223    }
224
225    public void setCall(CallSite call) {
226        this.call = call;
227    }
228
229    public double getElapsedTime() {
230        return end - start;
231    }
232
233    public Compilation getCompilation() {
234        return this;
235    }
236}
237