Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: dart/compiler/java/com/google/dart/runner/V8Launcher.java

Issue 9353015: Remove dartc optimizing backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix minor test issues Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 package com.google.dart.runner; 5 package com.google.dart.runner;
6 6
7 import com.google.common.collect.Lists; 7 import com.google.common.collect.Lists;
8 import com.google.debugging.sourcemap.SourceMapping;
9 import com.google.debugging.sourcemap.proto.Mapping.OriginalMapping;
10 8
11 import java.io.BufferedReader; 9 import java.io.BufferedReader;
12 import java.io.File; 10 import java.io.File;
13 import java.io.FileWriter; 11 import java.io.FileWriter;
14 import java.io.IOException; 12 import java.io.IOException;
15 import java.io.InputStream; 13 import java.io.InputStream;
16 import java.io.InputStreamReader; 14 import java.io.InputStreamReader;
17 import java.io.PrintStream; 15 import java.io.PrintStream;
18 import java.io.PrintWriter; 16 import java.io.PrintWriter;
19 import java.io.StringWriter; 17 import java.io.StringWriter;
(...skipping 28 matching lines...) Expand all
48 out.println(str); 46 out.println(str);
49 } 47 }
50 } catch (IOException e) { 48 } catch (IOException e) {
51 throw new AssertionError(e); 49 throw new AssertionError(e);
52 } 50 }
53 } 51 }
54 } 52 }
55 53
56 private static final String D8_ENVIRONMENT_VARIABLE = "D8_EXEC"; 54 private static final String D8_ENVIRONMENT_VARIABLE = "D8_EXEC";
57 55
58 private final SourceMapping appSourceMap;
59
60 private static final String EOL = System.getProperty("line.separator"); 56 private static final String EOL = System.getProperty("line.separator");
61 57
62 /** 58 public V8Launcher() {
63 *
64 */
65 public V8Launcher(SourceMapping appSourceMap) {
66 this.appSourceMap = appSourceMap;
67 } 59 }
68 60
69 @Override 61 @Override
70 public void execute(String jsScript, String sourceName, String[] args, RunnerO ptions options, 62 public void execute(String jsScript, String sourceName, String[] args, RunnerO ptions options,
71 PrintStream stdout, PrintStream stderr) 63 PrintStream stdout, PrintStream stderr)
72 throws RunnerError { 64 throws RunnerError {
73 if (!isConfigured()) { 65 if (!isConfigured()) {
74 throw new RunnerError("Please set the " + D8_ENVIRONMENT_VARIABLE + " envi ronment variable."); 66 throw new RunnerError("Please set the " + D8_ENVIRONMENT_VARIABLE + " envi ronment variable.");
75 } 67 }
76 File sourceFile; 68 File sourceFile;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 p.destroy(); 120 p.destroy();
129 } 121 }
130 if (exitValue != 0) { 122 if (exitValue != 0) {
131 StringWriter stringWriter = new StringWriter(); 123 StringWriter stringWriter = new StringWriter();
132 PrintWriter out = new PrintWriter(stringWriter); 124 PrintWriter out = new PrintWriter(stringWriter);
133 if (options.verbose()) { 125 if (options.verbose()) {
134 out.println(jsScript); 126 out.println(jsScript);
135 } 127 }
136 out.println("Execution failed."); 128 out.println("Execution failed.");
137 129
138 String str = mapStackEntry(decodeStackTraceFromString(stdOutLines), appS ourceMap);
139 if (str != null) {
140 out.println("Mapped stack trace:");
141 out.println(str);
142 out.println("");
143 }
144 out.println("V8 execution returned non-zero exit-code: " + p.exitValue() ); 130 out.println("V8 execution returned non-zero exit-code: " + p.exitValue() );
145 out.flush(); 131 out.flush();
146 throw new RunnerError(stringWriter.toString()); 132 throw new RunnerError(stringWriter.toString());
147 } 133 }
148 } finally { 134 } finally {
149 sourceFile.delete(); 135 sourceFile.delete();
150 } 136 }
151 } 137 }
152 138
153 private String mapStackEntry(List<StackEntry> entries, SourceMapping map) {
154 if (entries != null) {
155 StringBuilder sb = new StringBuilder();
156 for (StackEntry entry : entries) {
157 SourceMapping sm = getSourceMapForFile(entry.file, map);
158 // TODO(johnlenz): Try to translate the method name.
159 String method = (entry.method.isEmpty()) ? "" : " (" + entry.method + ") ";
160 if (sm != null) {
161 OriginalMapping mapping = sm.getMappingForLine(entry.line, entry.colum n);
162 if (mapping != null) {
163 String file = mapping.getOriginalFile();
164 int line = mapping.getLineNumber();
165 int column = mapping.getColumnPosition();
166 sb.append(" at MAPPED : " + file + ":" + line + ":" + column + m ethod + EOL);
167 continue;
168 }
169 }
170 sb.append(" at UNMAPPED: "
171 + entry.file + ":" + entry.line + ":" + entry.column + method + EOL) ;
172 }
173
174 return sb.toString();
175 }
176 return null;
177 }
178
179 SourceMapping getSourceMapForFile(String file, SourceMapping map) {
180 return map;
181 }
182
183 static class StackEntry {
184 String method;
185 String file;
186 int line;
187 int column;
188 }
189
190 private List<StackEntry> decodeStackTraceFromString(List<String> lines) {
191 List<StackEntry> entries = Lists.newArrayList();
192
193 boolean seenFirst = false;
194 for (String str : lines) {
195 StackEntry entry = decodeStackEntry(str);
196 if (entry == null) {
197 if (seenFirst) {
198 break;
199 } else {
200 continue;
201 }
202 } else {
203 seenFirst = true;
204 }
205 entries.add(entry);
206 }
207
208 return entries.isEmpty() ? null : entries;
209 }
210
211 private StackEntry decodeStackEntry(String str) {
212 final String PREFIX = " at ";
213 if (str.startsWith(PREFIX)) {
214 StackEntry entry = new StackEntry();
215 int start = str.indexOf("(");
216 int end = str.indexOf(")");
217 entry.method = "";
218 String location;
219 if (start == -1) {
220 location = str.substring(PREFIX.length());
221 } else {
222 entry.method = str.substring(7, start-1);
223 location = str.substring(start+1, end);
224 }
225 return decodeLocation(entry, location);
226 }
227 return null;
228 }
229
230 private StackEntry decodeLocation(StackEntry entry, String location) {
231 String[] parts = location.split(":");
232 if (parts.length >= 3) {
233 String file = parts[0];
234 for (int i = 1; i <= parts.length-3; i++) {
235 file += ":" + parts[i];
236 }
237 entry.file = file;
238 entry.line = Integer.valueOf(parts[parts.length - 2]);
239 entry.column = Integer.valueOf(parts[parts.length - 1]);
240 return entry;
241 }
242 return null;
243 }
244
245 private File writeTempFile(String name, String content) throws IOException { 139 private File writeTempFile(String name, String content) throws IOException {
246 // The first argument to createTempFile must be at least three characters lo ng, and be a 140 // The first argument to createTempFile must be at least three characters lo ng, and be a
247 // valid file-name. 141 // valid file-name.
248 name = name.replace('/', '_'); 142 name = name.replace('/', '_');
249 File file = File.createTempFile("dart_" + name, ".js"); 143 File file = File.createTempFile("dart_" + name, ".js");
250 FileWriter writer = new FileWriter(file); 144 FileWriter writer = new FileWriter(file);
251 try { 145 try {
252 writer.write(content); 146 writer.write(content);
253 } finally { 147 } finally {
254 writer.close(); 148 writer.close();
(...skipping 20 matching lines...) Expand all
275 * @return true if the D8_EXEC environment variable is correctly set up. 169 * @return true if the D8_EXEC environment variable is correctly set up.
276 */ 170 */
277 public static boolean isConfigured() { 171 public static boolean isConfigured() {
278 File file = v8Executable(); 172 File file = v8Executable();
279 if (file == null) { 173 if (file == null) {
280 return false; 174 return false;
281 } 175 }
282 return file.canExecute(); 176 return file.canExecute();
283 } 177 }
284 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698