comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiCompilationStatistics.java @ 5176:af59b4dfc9e4

compilation queue changes: * new CiCompilationStatistics * added new HotSpot compilation policy (-XX:CompilationPolicyChoice=4) * compile queue prioritizing (-G:+PriorityCompileQueue) * low-priority compilation threads (-G:+SlowCompileThreads) * dynamic compilation thread priority adjustment (-G:+DynamicCompilePriority)
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 29 Mar 2012 18:43:30 +0200
parents
children dc71b06d09f8
comparison
equal deleted inserted replaced
5175:a8c5283a835c 5176:af59b4dfc9e4
1 /*
2 * Copyright (c) 2012, 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 package com.oracle.max.cri.ci;
24
25 import java.io.*;
26 import java.lang.annotation.*;
27 import java.lang.reflect.*;
28 import java.util.*;
29 import java.util.concurrent.*;
30
31 import com.oracle.max.cri.ri.*;
32
33 @SuppressWarnings("unused")
34 public final class CiCompilationStatistics {
35
36 private static final long RESOLUTION = 100000000;
37 private static final boolean TIMELINE_ENABLED = System.getProperty("stats.timeline.file") != null;
38 private static final boolean COMPILATIONSTATS_ENABLED = System.getProperty("stats.compilations.file") != null;
39 private static final boolean ENABLED = TIMELINE_ENABLED || COMPILATIONSTATS_ENABLED;
40
41 private static final CiCompilationStatistics DUMMY = new CiCompilationStatistics(null);
42
43 private static ConcurrentLinkedDeque<CiCompilationStatistics> list = new ConcurrentLinkedDeque<>();
44
45 private static final ThreadLocal<Deque<CiCompilationStatistics>> current = new ThreadLocal<Deque<CiCompilationStatistics>>() {
46
47 @Override
48 protected Deque<CiCompilationStatistics> initialValue() {
49 return new ArrayDeque<>();
50 }
51 };
52
53 @Retention(RetentionPolicy.RUNTIME)
54 @Target(ElementType.FIELD)
55 private static @interface AbsoluteTimeValue {
56 }
57
58 @Retention(RetentionPolicy.RUNTIME)
59 @Target(ElementType.FIELD)
60 private static @interface TimeValue {
61 }
62
63 private static long zeroTime = System.nanoTime();
64
65 private final String holder;
66 private final String name;
67 private final String signature;
68 @AbsoluteTimeValue
69 private final long startTime;
70 @TimeValue
71 private long duration;
72 private int startInvCount;
73 private int endInvCount;
74 private int bytecodeCount;
75 private int codeSize;
76 private int deoptCount;
77
78 private CiCompilationStatistics(RiResolvedMethod method) {
79 if (method != null) {
80 holder = CiUtil.format("%H", method);
81 name = method.name();
82 signature = CiUtil.format("%p", method);
83 startTime = System.nanoTime();
84 startInvCount = method.invocationCount();
85 bytecodeCount = method.codeSize();
86 } else {
87 holder = "";
88 name = "";
89 signature = "";
90 startTime = 0;
91 }
92 }
93
94 public void finish(RiResolvedMethod method) {
95 if (ENABLED) {
96 duration = System.nanoTime() - startTime;
97 endInvCount = method.invocationCount();
98 codeSize = method.compiledCodeSize();
99 if (current.get().getLast() != this) {
100 throw new RuntimeException("mismatch in finish()");
101 }
102 current.get().removeLast();
103 }
104 }
105
106 public static CiCompilationStatistics current() {
107 return current.get().isEmpty() ? null : current.get().getLast();
108 }
109
110 public static CiCompilationStatistics create(RiResolvedMethod method) {
111 if (ENABLED) {
112 CiCompilationStatistics stats = new CiCompilationStatistics(method);
113 list.add(stats);
114 current.get().addLast(stats);
115 return stats;
116 } else {
117 return DUMMY;
118 }
119 }
120
121 @SuppressWarnings("deprecation")
122 public static void clear(String dumpName) {
123 if (!ENABLED) {
124 return;
125 }
126 try {
127 ConcurrentLinkedDeque<CiCompilationStatistics> snapshot = list;
128 long snapshotZeroTime = zeroTime;
129
130 list = new ConcurrentLinkedDeque<>();
131 zeroTime = System.nanoTime();
132
133 Date now = new Date();
134 String dateString = (now.getYear() + 1900) + "_" + (now.getMonth() + 1) + "_" + now.getDate() + " " + now.getHours() + "_" + now.getMinutes() + "_" + now.getSeconds();
135 try (PrintStream out = new PrintStream("compilations " + dateString + " " + dumpName + ".csv")) {
136 // output the list of all compilations
137
138 Field[] declaredFields = CiCompilationStatistics.class.getDeclaredFields();
139 ArrayList<Field> fields = new ArrayList<>();
140 for (Field field : declaredFields) {
141 if (!Modifier.isStatic(field.getModifiers())) {
142 fields.add(field);
143 }
144 }
145 for (Field field : fields) {
146 out.print(field.getName() + ";");
147 }
148 out.println();
149 for (CiCompilationStatistics stats : snapshot) {
150 for (Field field : fields) {
151 if (field.isAnnotationPresent(AbsoluteTimeValue.class)) {
152 double value = (field.getLong(stats) - snapshotZeroTime) / 1000000d;
153 out.print(String.format(Locale.ENGLISH, "%.3f", value) + ";");
154 } else if (field.isAnnotationPresent(TimeValue.class)) {
155 double value = field.getLong(stats) / 1000000d;
156 out.print(String.format(Locale.ENGLISH, "%.3f", value) + ";");
157 } else {
158 out.print(field.get(stats) + ";");
159 }
160 }
161 out.println();
162 }
163 }
164
165 String timelineFile = System.getProperty("stats.timeline.file");
166 if (timelineFile == null || timelineFile.isEmpty()) {
167 timelineFile = "timeline " + dateString;
168 }
169 try (FileOutputStream fos = new FileOutputStream(timelineFile + " " + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) {
170
171 long[] timeSpent = new long[10000];
172 int maxTick = 0;
173 for (CiCompilationStatistics stats : snapshot) {
174 long start = stats.startTime - snapshotZeroTime;
175 long duration = stats.duration;
176 if (start < 0) {
177 duration -= -start;
178 start = 0;
179 }
180
181 int tick = (int) (start / RESOLUTION);
182 long timeLeft = RESOLUTION - (start % RESOLUTION);
183
184 while (tick < timeSpent.length && duration > 0) {
185 if (tick > maxTick) {
186 maxTick = tick;
187 }
188 timeSpent[tick] += Math.min(timeLeft, duration);
189 duration -= timeLeft;
190 tick++;
191 timeLeft = RESOLUTION;
192 }
193 }
194 String timelineName = System.getProperty("stats.timeline.name");
195 if (timelineName != null && !timelineName.isEmpty()) {
196 out.print(timelineName + ";");
197 }
198 for (int i = 0; i <= maxTick; i++) {
199 out.print((timeSpent[i] * 100 / RESOLUTION) + ";");
200 }
201 out.println();
202 }
203 } catch (Exception e) {
204 throw new RuntimeException(e);
205 }
206 }
207
208 public void setDeoptCount(int count) {
209 this.deoptCount = count;
210 }
211 }