OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
6 // command line. | 6 // command line. |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include <cstdarg> | 12 #include <cstdarg> |
13 | 13 |
14 #include "bin/builtin.h" | 14 #include "bin/builtin.h" |
15 #include "bin/dartutils.h" | 15 #include "bin/dartutils.h" |
16 #include "bin/dfe.h" | 16 #include "bin/dfe.h" |
17 #include "bin/eventhandler.h" | 17 #include "bin/eventhandler.h" |
18 #include "bin/file.h" | 18 #include "bin/file.h" |
19 #include "bin/loader.h" | 19 #include "bin/loader.h" |
20 #include "bin/log.h" | 20 #include "bin/log.h" |
21 #include "bin/thread.h" | 21 #include "bin/thread.h" |
22 #include "bin/utils.h" | 22 #include "bin/utils.h" |
23 #include "bin/vmservice_impl.h" | 23 #include "bin/vmservice_impl.h" |
24 | 24 |
25 #include "include/dart_api.h" | 25 #include "include/dart_api.h" |
26 #include "include/dart_tools_api.h" | 26 #include "include/dart_tools_api.h" |
27 | 27 |
28 #include "platform/hashmap.h" | |
29 #include "platform/globals.h" | 28 #include "platform/globals.h" |
30 #include "platform/growable_array.h" | 29 #include "platform/growable_array.h" |
| 30 #include "platform/hashmap.h" |
31 | 31 |
32 namespace dart { | 32 namespace dart { |
33 namespace bin { | 33 namespace bin { |
34 | 34 |
35 DFE dfe; | 35 DFE dfe; |
36 | 36 |
37 // Exit code indicating an API error. | 37 // Exit code indicating an API error. |
38 static const int kApiErrorExitCode = 253; | 38 static const int kApiErrorExitCode = 253; |
39 // Exit code indicating a compilation error. | 39 // Exit code indicating a compilation error. |
40 static const int kCompilationErrorExitCode = 254; | 40 static const int kCompilationErrorExitCode = 254; |
41 // Exit code indicating an unhandled error that is not a compilation error. | 41 // Exit code indicating an unhandled error that is not a compilation error. |
42 static const int kErrorExitCode = 255; | 42 static const int kErrorExitCode = 255; |
43 | 43 |
44 #define CHECK_RESULT(result) \ | 44 #define CHECK_RESULT(result) \ |
45 if (Dart_IsError(result)) { \ | 45 if (Dart_IsError(result)) { \ |
46 intptr_t exit_code = 0; \ | 46 intptr_t exit_code = 0; \ |
47 Log::PrintErr("Error: %s\n", Dart_GetError(result)); \ | 47 Log::PrintErr("Error: %s\n", Dart_GetError(result)); \ |
48 if (Dart_IsCompilationError(result)) { \ | 48 if (Dart_IsCompilationError(result)) { \ |
49 exit_code = kCompilationErrorExitCode; \ | 49 exit_code = kCompilationErrorExitCode; \ |
50 } else if (Dart_IsApiError(result)) { \ | 50 } else if (Dart_IsApiError(result)) { \ |
51 exit_code = kApiErrorExitCode; \ | 51 exit_code = kApiErrorExitCode; \ |
52 } else { \ | 52 } else { \ |
53 exit_code = kErrorExitCode; \ | 53 exit_code = kErrorExitCode; \ |
54 } \ | 54 } \ |
55 Dart_ExitScope(); \ | 55 Dart_ExitScope(); \ |
56 Dart_ShutdownIsolate(); \ | 56 Dart_ShutdownIsolate(); \ |
57 exit(exit_code); \ | 57 exit(exit_code); \ |
58 } | 58 } |
59 | 59 |
60 | |
61 // The core snapshot to use when creating isolates. Normally NULL, but loaded | 60 // The core snapshot to use when creating isolates. Normally NULL, but loaded |
62 // from a file when creating script snapshots. | 61 // from a file when creating script snapshots. |
63 const uint8_t* isolate_snapshot_data = NULL; | 62 const uint8_t* isolate_snapshot_data = NULL; |
64 const uint8_t* isolate_snapshot_instructions = NULL; | 63 const uint8_t* isolate_snapshot_instructions = NULL; |
65 | 64 |
66 | |
67 // Global state that indicates whether a snapshot is to be created and | 65 // Global state that indicates whether a snapshot is to be created and |
68 // if so which file to write the snapshot into. | 66 // if so which file to write the snapshot into. |
69 enum SnapshotKind { | 67 enum SnapshotKind { |
70 kCore, | 68 kCore, |
71 kCoreJIT, | 69 kCoreJIT, |
72 kScript, | 70 kScript, |
73 kAppAOTBlobs, | 71 kAppAOTBlobs, |
74 kAppAOTAssembly, | 72 kAppAOTAssembly, |
75 }; | 73 }; |
76 static SnapshotKind snapshot_kind = kCore; | 74 static SnapshotKind snapshot_kind = kCore; |
77 static const char* vm_snapshot_data_filename = NULL; | 75 static const char* vm_snapshot_data_filename = NULL; |
78 static const char* vm_snapshot_instructions_filename = NULL; | 76 static const char* vm_snapshot_instructions_filename = NULL; |
79 static const char* isolate_snapshot_data_filename = NULL; | 77 static const char* isolate_snapshot_data_filename = NULL; |
80 static const char* isolate_snapshot_instructions_filename = NULL; | 78 static const char* isolate_snapshot_instructions_filename = NULL; |
81 static const char* assembly_filename = NULL; | 79 static const char* assembly_filename = NULL; |
82 static const char* script_snapshot_filename = NULL; | 80 static const char* script_snapshot_filename = NULL; |
83 static bool dependencies_only = false; | 81 static bool dependencies_only = false; |
84 static bool print_dependencies = false; | 82 static bool print_dependencies = false; |
85 static const char* dependencies_filename = NULL; | 83 static const char* dependencies_filename = NULL; |
86 | 84 |
87 | |
88 // Value of the --load-compilation-trace flag. | 85 // Value of the --load-compilation-trace flag. |
89 // (This pointer points into an argv buffer and does not need to be | 86 // (This pointer points into an argv buffer and does not need to be |
90 // free'd.) | 87 // free'd.) |
91 static const char* load_compilation_trace_filename = NULL; | 88 static const char* load_compilation_trace_filename = NULL; |
92 | 89 |
93 // Value of the --package-root flag. | 90 // Value of the --package-root flag. |
94 // (This pointer points into an argv buffer and does not need to be | 91 // (This pointer points into an argv buffer and does not need to be |
95 // free'd.) | 92 // free'd.) |
96 static const char* commandline_package_root = NULL; | 93 static const char* commandline_package_root = NULL; |
97 | 94 |
98 // Value of the --packages flag. | 95 // Value of the --packages flag. |
99 // (This pointer points into an argv buffer and does not need to be | 96 // (This pointer points into an argv buffer and does not need to be |
100 // free'd.) | 97 // free'd.) |
101 static const char* commandline_packages_file = NULL; | 98 static const char* commandline_packages_file = NULL; |
102 | 99 |
103 | |
104 // Global state which contains a pointer to the script name for which | 100 // Global state which contains a pointer to the script name for which |
105 // a snapshot needs to be created (NULL would result in the creation | 101 // a snapshot needs to be created (NULL would result in the creation |
106 // of a generic snapshot that contains only the corelibs). | 102 // of a generic snapshot that contains only the corelibs). |
107 static char* app_script_name = NULL; | 103 static char* app_script_name = NULL; |
108 | 104 |
109 // Global state that captures the entry point manifest files specified on the | 105 // Global state that captures the entry point manifest files specified on the |
110 // command line. | 106 // command line. |
111 static CommandLineOptions* entry_points_files = NULL; | 107 static CommandLineOptions* entry_points_files = NULL; |
112 | 108 |
113 static bool IsValidFlag(const char* name, | 109 static bool IsValidFlag(const char* name, |
114 const char* prefix, | 110 const char* prefix, |
115 intptr_t prefix_length) { | 111 intptr_t prefix_length) { |
116 intptr_t name_length = strlen(name); | 112 intptr_t name_length = strlen(name); |
117 return ((name_length > prefix_length) && | 113 return ((name_length > prefix_length) && |
118 (strncmp(name, prefix, prefix_length) == 0)); | 114 (strncmp(name, prefix, prefix_length) == 0)); |
119 } | 115 } |
120 | 116 |
121 | |
122 // The environment provided through the command line using -D options. | 117 // The environment provided through the command line using -D options. |
123 static dart::HashMap* environment = NULL; | 118 static dart::HashMap* environment = NULL; |
124 | 119 |
125 static void* GetHashmapKeyFromString(char* key) { | 120 static void* GetHashmapKeyFromString(char* key) { |
126 return reinterpret_cast<void*>(key); | 121 return reinterpret_cast<void*>(key); |
127 } | 122 } |
128 | 123 |
129 static bool ProcessEnvironmentOption(const char* arg) { | 124 static bool ProcessEnvironmentOption(const char* arg) { |
130 ASSERT(arg != NULL); | 125 ASSERT(arg != NULL); |
131 if (*arg == '\0') { | 126 if (*arg == '\0') { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 name[name_len] = '\0'; | 159 name[name_len] = '\0'; |
165 value = strdup(equals_pos + 1); | 160 value = strdup(equals_pos + 1); |
166 } | 161 } |
167 HashMap::Entry* entry = environment->Lookup(GetHashmapKeyFromString(name), | 162 HashMap::Entry* entry = environment->Lookup(GetHashmapKeyFromString(name), |
168 HashMap::StringHash(name), true); | 163 HashMap::StringHash(name), true); |
169 ASSERT(entry != NULL); // Lookup adds an entry if key not found. | 164 ASSERT(entry != NULL); // Lookup adds an entry if key not found. |
170 entry->value = value; | 165 entry->value = value; |
171 return true; | 166 return true; |
172 } | 167 } |
173 | 168 |
174 | |
175 static Dart_Handle EnvironmentCallback(Dart_Handle name) { | 169 static Dart_Handle EnvironmentCallback(Dart_Handle name) { |
176 uint8_t* utf8_array; | 170 uint8_t* utf8_array; |
177 intptr_t utf8_len; | 171 intptr_t utf8_len; |
178 Dart_Handle result = Dart_Null(); | 172 Dart_Handle result = Dart_Null(); |
179 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len); | 173 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len); |
180 if (Dart_IsError(handle)) { | 174 if (Dart_IsError(handle)) { |
181 handle = Dart_ThrowException( | 175 handle = Dart_ThrowException( |
182 DartUtils::NewDartArgumentError(Dart_GetError(handle))); | 176 DartUtils::NewDartArgumentError(Dart_GetError(handle))); |
183 } else { | 177 } else { |
184 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1)); | 178 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1)); |
(...skipping 10 matching lines...) Expand all Loading... |
195 } | 189 } |
196 if (value != NULL) { | 190 if (value != NULL) { |
197 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), | 191 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), |
198 strlen(value)); | 192 strlen(value)); |
199 } | 193 } |
200 free(name_chars); | 194 free(name_chars); |
201 } | 195 } |
202 return result; | 196 return result; |
203 } | 197 } |
204 | 198 |
205 | |
206 static const char* ProcessOption(const char* option, const char* name) { | 199 static const char* ProcessOption(const char* option, const char* name) { |
207 const intptr_t length = strlen(name); | 200 const intptr_t length = strlen(name); |
208 if (strncmp(option, name, length) == 0) { | 201 if (strncmp(option, name, length) == 0) { |
209 return (option + length); | 202 return (option + length); |
210 } | 203 } |
211 return NULL; | 204 return NULL; |
212 } | 205 } |
213 | 206 |
214 | |
215 static bool ProcessSnapshotKindOption(const char* option) { | 207 static bool ProcessSnapshotKindOption(const char* option) { |
216 const char* kind = ProcessOption(option, "--snapshot_kind="); | 208 const char* kind = ProcessOption(option, "--snapshot_kind="); |
217 if (kind == NULL) { | 209 if (kind == NULL) { |
218 kind = ProcessOption(option, "--snapshot-kind="); | 210 kind = ProcessOption(option, "--snapshot-kind="); |
219 } | 211 } |
220 if (kind == NULL) { | 212 if (kind == NULL) { |
221 return false; | 213 return false; |
222 } | 214 } |
223 if (strcmp(kind, "core-jit") == 0) { | 215 if (strcmp(kind, "core-jit") == 0) { |
224 snapshot_kind = kCoreJIT; | 216 snapshot_kind = kCoreJIT; |
(...skipping 11 matching lines...) Expand all Loading... |
236 snapshot_kind = kAppAOTAssembly; | 228 snapshot_kind = kAppAOTAssembly; |
237 return true; | 229 return true; |
238 } | 230 } |
239 Log::PrintErr( | 231 Log::PrintErr( |
240 "Unrecognized snapshot kind: '%s'\nValid kinds are: " | 232 "Unrecognized snapshot kind: '%s'\nValid kinds are: " |
241 "core, script, app-aot-blobs, app-aot-assembly\n", | 233 "core, script, app-aot-blobs, app-aot-assembly\n", |
242 kind); | 234 kind); |
243 return false; | 235 return false; |
244 } | 236 } |
245 | 237 |
246 | |
247 static bool ProcessVmSnapshotDataOption(const char* option) { | 238 static bool ProcessVmSnapshotDataOption(const char* option) { |
248 const char* name = ProcessOption(option, "--vm_snapshot_data="); | 239 const char* name = ProcessOption(option, "--vm_snapshot_data="); |
249 if (name == NULL) { | 240 if (name == NULL) { |
250 name = ProcessOption(option, "--vm-snapshot-data="); | 241 name = ProcessOption(option, "--vm-snapshot-data="); |
251 } | 242 } |
252 if (name != NULL) { | 243 if (name != NULL) { |
253 vm_snapshot_data_filename = name; | 244 vm_snapshot_data_filename = name; |
254 return true; | 245 return true; |
255 } | 246 } |
256 return false; | 247 return false; |
257 } | 248 } |
258 | 249 |
259 | |
260 static bool ProcessVmSnapshotInstructionsOption(const char* option) { | 250 static bool ProcessVmSnapshotInstructionsOption(const char* option) { |
261 const char* name = ProcessOption(option, "--vm_snapshot_instructions="); | 251 const char* name = ProcessOption(option, "--vm_snapshot_instructions="); |
262 if (name == NULL) { | 252 if (name == NULL) { |
263 name = ProcessOption(option, "--vm-snapshot-instructions="); | 253 name = ProcessOption(option, "--vm-snapshot-instructions="); |
264 } | 254 } |
265 if (name != NULL) { | 255 if (name != NULL) { |
266 vm_snapshot_instructions_filename = name; | 256 vm_snapshot_instructions_filename = name; |
267 return true; | 257 return true; |
268 } | 258 } |
269 return false; | 259 return false; |
270 } | 260 } |
271 | 261 |
272 | |
273 static bool ProcessIsolateSnapshotDataOption(const char* option) { | 262 static bool ProcessIsolateSnapshotDataOption(const char* option) { |
274 const char* name = ProcessOption(option, "--isolate_snapshot_data="); | 263 const char* name = ProcessOption(option, "--isolate_snapshot_data="); |
275 if (name == NULL) { | 264 if (name == NULL) { |
276 name = ProcessOption(option, "--isolate-snapshot-data="); | 265 name = ProcessOption(option, "--isolate-snapshot-data="); |
277 } | 266 } |
278 if (name != NULL) { | 267 if (name != NULL) { |
279 isolate_snapshot_data_filename = name; | 268 isolate_snapshot_data_filename = name; |
280 return true; | 269 return true; |
281 } | 270 } |
282 return false; | 271 return false; |
283 } | 272 } |
284 | 273 |
285 | |
286 static bool ProcessIsolateSnapshotInstructionsOption(const char* option) { | 274 static bool ProcessIsolateSnapshotInstructionsOption(const char* option) { |
287 const char* name = ProcessOption(option, "--isolate_snapshot_instructions="); | 275 const char* name = ProcessOption(option, "--isolate_snapshot_instructions="); |
288 if (name == NULL) { | 276 if (name == NULL) { |
289 name = ProcessOption(option, "--isolate-snapshot-instructions="); | 277 name = ProcessOption(option, "--isolate-snapshot-instructions="); |
290 } | 278 } |
291 if (name != NULL) { | 279 if (name != NULL) { |
292 isolate_snapshot_instructions_filename = name; | 280 isolate_snapshot_instructions_filename = name; |
293 return true; | 281 return true; |
294 } | 282 } |
295 return false; | 283 return false; |
296 } | 284 } |
297 | 285 |
298 | |
299 static bool ProcessAssemblyOption(const char* option) { | 286 static bool ProcessAssemblyOption(const char* option) { |
300 const char* name = ProcessOption(option, "--assembly="); | 287 const char* name = ProcessOption(option, "--assembly="); |
301 if (name != NULL) { | 288 if (name != NULL) { |
302 assembly_filename = name; | 289 assembly_filename = name; |
303 return true; | 290 return true; |
304 } | 291 } |
305 return false; | 292 return false; |
306 } | 293 } |
307 | 294 |
308 | |
309 static bool ProcessScriptSnapshotOption(const char* option) { | 295 static bool ProcessScriptSnapshotOption(const char* option) { |
310 const char* name = ProcessOption(option, "--script_snapshot="); | 296 const char* name = ProcessOption(option, "--script_snapshot="); |
311 if (name == NULL) { | 297 if (name == NULL) { |
312 name = ProcessOption(option, "--script-snapshot="); | 298 name = ProcessOption(option, "--script-snapshot="); |
313 } | 299 } |
314 if (name != NULL) { | 300 if (name != NULL) { |
315 script_snapshot_filename = name; | 301 script_snapshot_filename = name; |
316 return true; | 302 return true; |
317 } | 303 } |
318 return false; | 304 return false; |
319 } | 305 } |
320 | 306 |
321 | |
322 static bool ProcessDependenciesOption(const char* option) { | 307 static bool ProcessDependenciesOption(const char* option) { |
323 const char* name = ProcessOption(option, "--dependencies="); | 308 const char* name = ProcessOption(option, "--dependencies="); |
324 if (name != NULL) { | 309 if (name != NULL) { |
325 dependencies_filename = name; | 310 dependencies_filename = name; |
326 return true; | 311 return true; |
327 } | 312 } |
328 return false; | 313 return false; |
329 } | 314 } |
330 | 315 |
331 | |
332 static bool ProcessDependenciesOnlyOption(const char* option) { | 316 static bool ProcessDependenciesOnlyOption(const char* option) { |
333 const char* name = ProcessOption(option, "--dependencies_only"); | 317 const char* name = ProcessOption(option, "--dependencies_only"); |
334 if (name == NULL) { | 318 if (name == NULL) { |
335 name = ProcessOption(option, "--dependencies-only"); | 319 name = ProcessOption(option, "--dependencies-only"); |
336 } | 320 } |
337 if (name != NULL) { | 321 if (name != NULL) { |
338 dependencies_only = true; | 322 dependencies_only = true; |
339 return true; | 323 return true; |
340 } | 324 } |
341 return false; | 325 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
358 if (name == NULL) { | 342 if (name == NULL) { |
359 name = ProcessOption(option, "--embedder-entry-points-manifest="); | 343 name = ProcessOption(option, "--embedder-entry-points-manifest="); |
360 } | 344 } |
361 if (name != NULL) { | 345 if (name != NULL) { |
362 entry_points_files->AddArgument(name); | 346 entry_points_files->AddArgument(name); |
363 return true; | 347 return true; |
364 } | 348 } |
365 return false; | 349 return false; |
366 } | 350 } |
367 | 351 |
368 | |
369 static bool ProcessLoadCompilationTraceOption(const char* option) { | 352 static bool ProcessLoadCompilationTraceOption(const char* option) { |
370 const char* name = ProcessOption(option, "--load_compilation_trace="); | 353 const char* name = ProcessOption(option, "--load_compilation_trace="); |
371 if (name == NULL) { | 354 if (name == NULL) { |
372 name = ProcessOption(option, "--load-compilation-trace="); | 355 name = ProcessOption(option, "--load-compilation-trace="); |
373 } | 356 } |
374 if (name != NULL) { | 357 if (name != NULL) { |
375 load_compilation_trace_filename = name; | 358 load_compilation_trace_filename = name; |
376 return true; | 359 return true; |
377 } | 360 } |
378 return false; | 361 return false; |
379 } | 362 } |
380 | 363 |
381 | |
382 static bool ProcessPackageRootOption(const char* option) { | 364 static bool ProcessPackageRootOption(const char* option) { |
383 const char* name = ProcessOption(option, "--package_root="); | 365 const char* name = ProcessOption(option, "--package_root="); |
384 if (name == NULL) { | 366 if (name == NULL) { |
385 name = ProcessOption(option, "--package-root="); | 367 name = ProcessOption(option, "--package-root="); |
386 } | 368 } |
387 if (name != NULL) { | 369 if (name != NULL) { |
388 commandline_package_root = name; | 370 commandline_package_root = name; |
389 return true; | 371 return true; |
390 } | 372 } |
391 return false; | 373 return false; |
392 } | 374 } |
393 | 375 |
394 | |
395 static bool ProcessPackagesOption(const char* option) { | 376 static bool ProcessPackagesOption(const char* option) { |
396 const char* name = ProcessOption(option, "--packages="); | 377 const char* name = ProcessOption(option, "--packages="); |
397 if (name != NULL) { | 378 if (name != NULL) { |
398 commandline_packages_file = name; | 379 commandline_packages_file = name; |
399 return true; | 380 return true; |
400 } | 381 } |
401 return false; | 382 return false; |
402 } | 383 } |
403 | 384 |
404 | |
405 static bool ProcessURLmappingOption(const char* option) { | 385 static bool ProcessURLmappingOption(const char* option) { |
406 const char* mapping = ProcessOption(option, "--url_mapping="); | 386 const char* mapping = ProcessOption(option, "--url_mapping="); |
407 if (mapping == NULL) { | 387 if (mapping == NULL) { |
408 mapping = ProcessOption(option, "--url-mapping="); | 388 mapping = ProcessOption(option, "--url-mapping="); |
409 } | 389 } |
410 if (mapping != NULL) { | 390 if (mapping != NULL) { |
411 DartUtils::url_mapping->AddArgument(mapping); | 391 DartUtils::url_mapping->AddArgument(mapping); |
412 return true; | 392 return true; |
413 } | 393 } |
414 return false; | 394 return false; |
415 } | 395 } |
416 | 396 |
417 | |
418 static bool IsSnapshottingForPrecompilation() { | 397 static bool IsSnapshottingForPrecompilation() { |
419 return (snapshot_kind == kAppAOTBlobs) || (snapshot_kind == kAppAOTAssembly); | 398 return (snapshot_kind == kAppAOTBlobs) || (snapshot_kind == kAppAOTAssembly); |
420 } | 399 } |
421 | 400 |
422 | |
423 // Parse out the command line arguments. Returns -1 if the arguments | 401 // Parse out the command line arguments. Returns -1 if the arguments |
424 // are incorrect, 0 otherwise. | 402 // are incorrect, 0 otherwise. |
425 static int ParseArguments(int argc, | 403 static int ParseArguments(int argc, |
426 char** argv, | 404 char** argv, |
427 CommandLineOptions* vm_options, | 405 CommandLineOptions* vm_options, |
428 char** script_name) { | 406 char** script_name) { |
429 const char* kPrefix = "-"; | 407 const char* kPrefix = "-"; |
430 const intptr_t kPrefixLen = strlen(kPrefix); | 408 const intptr_t kPrefixLen = strlen(kPrefix); |
431 | 409 |
432 // Skip the binary name. | 410 // Skip the binary name. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { | 516 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { |
539 Log::PrintErr( | 517 Log::PrintErr( |
540 "Building an AOT snapshot requires at least one embedder " | 518 "Building an AOT snapshot requires at least one embedder " |
541 "entry points manifest.\n\n"); | 519 "entry points manifest.\n\n"); |
542 return -1; | 520 return -1; |
543 } | 521 } |
544 | 522 |
545 return 0; | 523 return 0; |
546 } | 524 } |
547 | 525 |
548 | |
549 static void WriteFile(const char* filename, | 526 static void WriteFile(const char* filename, |
550 const uint8_t* buffer, | 527 const uint8_t* buffer, |
551 const intptr_t size) { | 528 const intptr_t size) { |
552 File* file = File::Open(filename, File::kWriteTruncate); | 529 File* file = File::Open(filename, File::kWriteTruncate); |
553 if (file == NULL) { | 530 if (file == NULL) { |
554 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); | 531 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
555 Dart_ExitScope(); | 532 Dart_ExitScope(); |
556 Dart_ShutdownIsolate(); | 533 Dart_ShutdownIsolate(); |
557 exit(kErrorExitCode); | 534 exit(kErrorExitCode); |
558 } | 535 } |
559 if (!file->WriteFully(buffer, size)) { | 536 if (!file->WriteFully(buffer, size)) { |
560 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); | 537 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
561 Dart_ExitScope(); | 538 Dart_ExitScope(); |
562 Dart_ShutdownIsolate(); | 539 Dart_ShutdownIsolate(); |
563 exit(kErrorExitCode); | 540 exit(kErrorExitCode); |
564 } | 541 } |
565 file->Release(); | 542 file->Release(); |
566 } | 543 } |
567 | 544 |
568 | |
569 static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) { | 545 static void ReadFile(const char* filename, uint8_t** buffer, intptr_t* size) { |
570 File* file = File::Open(filename, File::kRead); | 546 File* file = File::Open(filename, File::kRead); |
571 if (file == NULL) { | 547 if (file == NULL) { |
572 Log::PrintErr("Unable to open file %s\n", filename); | 548 Log::PrintErr("Unable to open file %s\n", filename); |
573 Dart_ExitScope(); | 549 Dart_ExitScope(); |
574 Dart_ShutdownIsolate(); | 550 Dart_ShutdownIsolate(); |
575 exit(kErrorExitCode); | 551 exit(kErrorExitCode); |
576 } | 552 } |
577 *size = file->Length(); | 553 *size = file->Length(); |
578 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); | 554 *buffer = reinterpret_cast<uint8_t*>(malloc(*size)); |
579 if (!file->ReadFully(*buffer, *size)) { | 555 if (!file->ReadFully(*buffer, *size)) { |
580 Log::PrintErr("Unable to read file %s\n", filename); | 556 Log::PrintErr("Unable to read file %s\n", filename); |
581 Dart_ExitScope(); | 557 Dart_ExitScope(); |
582 Dart_ShutdownIsolate(); | 558 Dart_ShutdownIsolate(); |
583 exit(kErrorExitCode); | 559 exit(kErrorExitCode); |
584 } | 560 } |
585 file->Release(); | 561 file->Release(); |
586 } | 562 } |
587 | 563 |
588 | |
589 class UriResolverIsolateScope { | 564 class UriResolverIsolateScope { |
590 public: | 565 public: |
591 UriResolverIsolateScope() { | 566 UriResolverIsolateScope() { |
592 ASSERT(isolate != NULL); | 567 ASSERT(isolate != NULL); |
593 snapshotted_isolate_ = Dart_CurrentIsolate(); | 568 snapshotted_isolate_ = Dart_CurrentIsolate(); |
594 Dart_ExitIsolate(); | 569 Dart_ExitIsolate(); |
595 Dart_EnterIsolate(isolate); | 570 Dart_EnterIsolate(isolate); |
596 Dart_EnterScope(); | 571 Dart_EnterScope(); |
597 } | 572 } |
598 | 573 |
599 ~UriResolverIsolateScope() { | 574 ~UriResolverIsolateScope() { |
600 ASSERT(snapshotted_isolate_ != NULL); | 575 ASSERT(snapshotted_isolate_ != NULL); |
601 Dart_ExitScope(); | 576 Dart_ExitScope(); |
602 Dart_ExitIsolate(); | 577 Dart_ExitIsolate(); |
603 Dart_EnterIsolate(snapshotted_isolate_); | 578 Dart_EnterIsolate(snapshotted_isolate_); |
604 } | 579 } |
605 | 580 |
606 static Dart_Isolate isolate; | 581 static Dart_Isolate isolate; |
607 | 582 |
608 private: | 583 private: |
609 Dart_Isolate snapshotted_isolate_; | 584 Dart_Isolate snapshotted_isolate_; |
610 | 585 |
611 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); | 586 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); |
612 }; | 587 }; |
613 | 588 |
614 | |
615 Dart_Isolate UriResolverIsolateScope::isolate = NULL; | 589 Dart_Isolate UriResolverIsolateScope::isolate = NULL; |
616 | 590 |
617 | |
618 static void AddDependency(const char* uri_string) { | 591 static void AddDependency(const char* uri_string) { |
619 IsolateData* isolate_data = | 592 IsolateData* isolate_data = |
620 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 593 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
621 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); | 594 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); |
622 if (dependencies != NULL) { | 595 if (dependencies != NULL) { |
623 dependencies->Add(strdup(uri_string)); | 596 dependencies->Add(strdup(uri_string)); |
624 } | 597 } |
625 } | 598 } |
626 | 599 |
627 | |
628 static Dart_Handle LoadUrlContents(const char* uri_string) { | 600 static Dart_Handle LoadUrlContents(const char* uri_string) { |
629 bool failed = false; | 601 bool failed = false; |
630 char* error_string = NULL; | 602 char* error_string = NULL; |
631 uint8_t* payload = NULL; | 603 uint8_t* payload = NULL; |
632 intptr_t payload_length = 0; | 604 intptr_t payload_length = 0; |
633 // Switch to the UriResolver Isolate and load the script. | 605 // Switch to the UriResolver Isolate and load the script. |
634 { | 606 { |
635 UriResolverIsolateScope scope; | 607 UriResolverIsolateScope scope; |
636 | 608 |
637 Dart_Handle resolved_uri = Dart_NewStringFromCString(uri_string); | 609 Dart_Handle resolved_uri = Dart_NewStringFromCString(uri_string); |
(...skipping 11 matching lines...) Expand all Loading... |
649 if (!failed) { | 621 if (!failed) { |
650 result = Dart_NewStringFromUTF8(payload, payload_length); | 622 result = Dart_NewStringFromUTF8(payload, payload_length); |
651 free(payload); | 623 free(payload); |
652 } else { | 624 } else { |
653 result = Dart_NewApiError(error_string); | 625 result = Dart_NewApiError(error_string); |
654 free(error_string); | 626 free(error_string); |
655 } | 627 } |
656 return result; | 628 return result; |
657 } | 629 } |
658 | 630 |
659 | |
660 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { | 631 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { |
661 bool failed = false; | 632 bool failed = false; |
662 char* result_string = NULL; | 633 char* result_string = NULL; |
663 | 634 |
664 { | 635 { |
665 UriResolverIsolateScope scope; | 636 UriResolverIsolateScope scope; |
666 | 637 |
667 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver | 638 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver |
668 // isolate. | 639 // isolate. |
669 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory( | 640 Dart_Handle result = DartUtils::ResolveUriInWorkingDirectory( |
670 DartUtils::NewString(script_uri)); | 641 DartUtils::NewString(script_uri)); |
671 if (Dart_IsError(result)) { | 642 if (Dart_IsError(result)) { |
672 failed = true; | 643 failed = true; |
673 result_string = strdup(Dart_GetError(result)); | 644 result_string = strdup(Dart_GetError(result)); |
674 } else { | 645 } else { |
675 result_string = strdup(DartUtils::GetStringValue(result)); | 646 result_string = strdup(DartUtils::GetStringValue(result)); |
676 } | 647 } |
677 } | 648 } |
678 | 649 |
679 Dart_Handle result = failed ? Dart_NewApiError(result_string) | 650 Dart_Handle result = failed ? Dart_NewApiError(result_string) |
680 : DartUtils::NewString(result_string); | 651 : DartUtils::NewString(result_string); |
681 free(result_string); | 652 free(result_string); |
682 return result; | 653 return result; |
683 } | 654 } |
684 | 655 |
685 | |
686 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { | 656 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { |
687 // First resolve the specified script uri with respect to the original | 657 // First resolve the specified script uri with respect to the original |
688 // working directory. | 658 // working directory. |
689 Dart_Handle resolved_uri = ResolveUriInWorkingDirectory(script_name); | 659 Dart_Handle resolved_uri = ResolveUriInWorkingDirectory(script_name); |
690 if (Dart_IsError(resolved_uri)) { | 660 if (Dart_IsError(resolved_uri)) { |
691 return resolved_uri; | 661 return resolved_uri; |
692 } | 662 } |
693 // Now load the contents of the specified uri. | 663 // Now load the contents of the specified uri. |
694 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); | 664 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); |
695 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 665 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
696 | 666 |
697 if (Dart_IsError(source)) { | 667 if (Dart_IsError(source)) { |
698 return source; | 668 return source; |
699 } | 669 } |
700 if ((snapshot_kind == kCore) || (snapshot_kind == kCoreJIT)) { | 670 if ((snapshot_kind == kCore) || (snapshot_kind == kCoreJIT)) { |
701 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); | 671 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); |
702 } else { | 672 } else { |
703 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); | 673 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
704 } | 674 } |
705 } | 675 } |
706 | 676 |
707 | |
708 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { | 677 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { |
709 if (DartUtils::IsDartBuiltinLibURL(url)) { | 678 if (DartUtils::IsDartBuiltinLibURL(url)) { |
710 return Builtin::kBuiltinLibrary; | 679 return Builtin::kBuiltinLibrary; |
711 } | 680 } |
712 if (DartUtils::IsDartIOLibURL(url)) { | 681 if (DartUtils::IsDartIOLibURL(url)) { |
713 return Builtin::kIOLibrary; | 682 return Builtin::kIOLibrary; |
714 } | 683 } |
715 return Builtin::kInvalidLibrary; | 684 return Builtin::kInvalidLibrary; |
716 } | 685 } |
717 | 686 |
718 | |
719 // Generates a depfile like gcc -M -MF. Must be consumable by Ninja. | 687 // Generates a depfile like gcc -M -MF. Must be consumable by Ninja. |
720 class DependenciesFileWriter : public ValueObject { | 688 class DependenciesFileWriter : public ValueObject { |
721 public: | 689 public: |
722 DependenciesFileWriter() : dependencies_(NULL), file_(NULL), success_(true) {} | 690 DependenciesFileWriter() : dependencies_(NULL), file_(NULL), success_(true) {} |
723 | 691 |
724 void WriteDependencies(MallocGrowableArray<char*>* dependencies) { | 692 void WriteDependencies(MallocGrowableArray<char*>* dependencies) { |
725 dependencies_ = dependencies; | 693 dependencies_ = dependencies; |
726 | 694 |
727 file_ = File::Open(dependencies_filename, File::kWriteTruncate); | 695 file_ = File::Open(dependencies_filename, File::kWriteTruncate); |
728 if (file_ == NULL) { | 696 if (file_ == NULL) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 free(escaped_path); | 777 free(escaped_path); |
810 } | 778 } |
811 | 779 |
812 void Write(const char* string) { success_ &= file_->Print("%s", string); } | 780 void Write(const char* string) { success_ &= file_->Print("%s", string); } |
813 | 781 |
814 MallocGrowableArray<char*>* dependencies_; | 782 MallocGrowableArray<char*>* dependencies_; |
815 File* file_; | 783 File* file_; |
816 bool success_; | 784 bool success_; |
817 }; | 785 }; |
818 | 786 |
819 | |
820 static void CreateAndWriteDependenciesFile() { | 787 static void CreateAndWriteDependenciesFile() { |
821 IsolateData* isolate_data = | 788 IsolateData* isolate_data = |
822 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 789 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
823 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); | 790 MallocGrowableArray<char*>* dependencies = isolate_data->dependencies(); |
824 if (dependencies == NULL) { | 791 if (dependencies == NULL) { |
825 return; | 792 return; |
826 } | 793 } |
827 | 794 |
828 Loader::ResolveDependenciesAsFilePaths(); | 795 Loader::ResolveDependenciesAsFilePaths(); |
829 | 796 |
(...skipping 24 matching lines...) Expand all Loading... |
854 } | 821 } |
855 } | 822 } |
856 | 823 |
857 for (intptr_t i = 0; i < dependencies->length(); i++) { | 824 for (intptr_t i = 0; i < dependencies->length(); i++) { |
858 free(dependencies->At(i)); | 825 free(dependencies->At(i)); |
859 } | 826 } |
860 delete dependencies; | 827 delete dependencies; |
861 isolate_data->set_dependencies(NULL); | 828 isolate_data->set_dependencies(NULL); |
862 } | 829 } |
863 | 830 |
864 | |
865 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, | 831 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag, |
866 Dart_Handle library, | 832 Dart_Handle library, |
867 Dart_Handle url) { | 833 Dart_Handle url) { |
868 if (!Dart_IsLibrary(library)) { | 834 if (!Dart_IsLibrary(library)) { |
869 return Dart_NewApiError("not a library"); | 835 return Dart_NewApiError("not a library"); |
870 } | 836 } |
871 Dart_Handle library_url = Dart_LibraryUrl(library); | 837 Dart_Handle library_url = Dart_LibraryUrl(library); |
872 if (Dart_IsError(library_url)) { | 838 if (Dart_IsError(library_url)) { |
873 return Dart_NewApiError("accessing library url failed"); | 839 return Dart_NewApiError("accessing library url failed"); |
874 } | 840 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 return source; | 899 return source; |
934 } | 900 } |
935 if (tag == Dart_kImportTag) { | 901 if (tag == Dart_kImportTag) { |
936 return Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); | 902 return Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
937 } else { | 903 } else { |
938 ASSERT(tag == Dart_kSourceTag); | 904 ASSERT(tag == Dart_kSourceTag); |
939 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); | 905 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); |
940 } | 906 } |
941 } | 907 } |
942 | 908 |
943 | |
944 static Dart_Handle LoadGenericSnapshotCreationScript( | 909 static Dart_Handle LoadGenericSnapshotCreationScript( |
945 Builtin::BuiltinLibraryId id) { | 910 Builtin::BuiltinLibraryId id) { |
946 Dart_Handle source = Builtin::Source(id); | 911 Dart_Handle source = Builtin::Source(id); |
947 if (Dart_IsError(source)) { | 912 if (Dart_IsError(source)) { |
948 return source; // source contains the error string. | 913 return source; // source contains the error string. |
949 } | 914 } |
950 Dart_Handle lib; | 915 Dart_Handle lib; |
951 // Load the builtin library to make it available in the snapshot | 916 // Load the builtin library to make it available in the snapshot |
952 // for importing. | 917 // for importing. |
953 lib = Builtin::LoadAndCheckLibrary(id); | 918 lib = Builtin::LoadAndCheckLibrary(id); |
954 ASSERT(!Dart_IsError(lib)); | 919 ASSERT(!Dart_IsError(lib)); |
955 return lib; | 920 return lib; |
956 } | 921 } |
957 | 922 |
958 | |
959 // clang-format off | 923 // clang-format off |
960 static void PrintUsage() { | 924 static void PrintUsage() { |
961 Log::PrintErr( | 925 Log::PrintErr( |
962 "Usage: \n" | 926 "Usage: \n" |
963 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" | 927 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" |
964 " \n" | 928 " \n" |
965 " Global options: \n" | 929 " Global options: \n" |
966 " --package_root=<path> Where to find packages, that is, \n" | 930 " --package_root=<path> Where to find packages, that is, \n" |
967 " package:... imports. \n" | 931 " package:... imports. \n" |
968 " \n" | 932 " \n" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 " manifest is a comma separated list of three elements. The first entry is \n" | 987 " manifest is a comma separated list of three elements. The first entry is \n" |
1024 " the library URI, the second entry is the class name and the final entry \n" | 988 " the library URI, the second entry is the class name and the final entry \n" |
1025 " the function name. The file must be terminated with a newline character. \n" | 989 " the function name. The file must be terminated with a newline character. \n" |
1026 " \n" | 990 " \n" |
1027 " Example: \n" | 991 " Example: \n" |
1028 " dart:something,SomeClass,doSomething \n" | 992 " dart:something,SomeClass,doSomething \n" |
1029 "\n"); | 993 "\n"); |
1030 } | 994 } |
1031 // clang-format on | 995 // clang-format on |
1032 | 996 |
1033 | |
1034 static const char StubNativeFunctionName[] = "StubNativeFunction"; | 997 static const char StubNativeFunctionName[] = "StubNativeFunction"; |
1035 | 998 |
1036 | |
1037 void StubNativeFunction(Dart_NativeArguments arguments) { | 999 void StubNativeFunction(Dart_NativeArguments arguments) { |
1038 // This is a stub function for the resolver | 1000 // This is a stub function for the resolver |
1039 Dart_SetReturnValue( | 1001 Dart_SetReturnValue( |
1040 arguments, Dart_NewApiError("<EMBEDDER DID NOT SETUP NATIVE RESOLVER>")); | 1002 arguments, Dart_NewApiError("<EMBEDDER DID NOT SETUP NATIVE RESOLVER>")); |
1041 } | 1003 } |
1042 | 1004 |
1043 | |
1044 static Dart_NativeFunction StubNativeLookup(Dart_Handle name, | 1005 static Dart_NativeFunction StubNativeLookup(Dart_Handle name, |
1045 int argument_count, | 1006 int argument_count, |
1046 bool* auto_setup_scope) { | 1007 bool* auto_setup_scope) { |
1047 return &StubNativeFunction; | 1008 return &StubNativeFunction; |
1048 } | 1009 } |
1049 | 1010 |
1050 | |
1051 static const uint8_t* StubNativeSymbol(Dart_NativeFunction nf) { | 1011 static const uint8_t* StubNativeSymbol(Dart_NativeFunction nf) { |
1052 return reinterpret_cast<const uint8_t*>(StubNativeFunctionName); | 1012 return reinterpret_cast<const uint8_t*>(StubNativeFunctionName); |
1053 } | 1013 } |
1054 | 1014 |
1055 | |
1056 static void SetupStubNativeResolver(size_t lib_index, | 1015 static void SetupStubNativeResolver(size_t lib_index, |
1057 const Dart_QualifiedFunctionName* entry) { | 1016 const Dart_QualifiedFunctionName* entry) { |
1058 // TODO(24686): Remove this. | 1017 // TODO(24686): Remove this. |
1059 Dart_Handle library_string = Dart_NewStringFromCString(entry->library_uri); | 1018 Dart_Handle library_string = Dart_NewStringFromCString(entry->library_uri); |
1060 DART_CHECK_VALID(library_string); | 1019 DART_CHECK_VALID(library_string); |
1061 Dart_Handle library = Dart_LookupLibrary(library_string); | 1020 Dart_Handle library = Dart_LookupLibrary(library_string); |
1062 // Embedder entry points may be setup in libraries that have not been | 1021 // Embedder entry points may be setup in libraries that have not been |
1063 // explicitly loaded by the application script. In such cases, library lookup | 1022 // explicitly loaded by the application script. In such cases, library lookup |
1064 // will fail. Manually load those libraries. | 1023 // will fail. Manually load those libraries. |
1065 if (Dart_IsError(library)) { | 1024 if (Dart_IsError(library)) { |
(...skipping 14 matching lines...) Expand all Loading... |
1080 // Do a fresh lookup | 1039 // Do a fresh lookup |
1081 library = Dart_LookupLibrary(library_string); | 1040 library = Dart_LookupLibrary(library_string); |
1082 } | 1041 } |
1083 | 1042 |
1084 DART_CHECK_VALID(library); | 1043 DART_CHECK_VALID(library); |
1085 Dart_Handle result = | 1044 Dart_Handle result = |
1086 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol); | 1045 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol); |
1087 DART_CHECK_VALID(result); | 1046 DART_CHECK_VALID(result); |
1088 } | 1047 } |
1089 | 1048 |
1090 | |
1091 // Iterate over all libraries and setup the stub native lookup. This must be | 1049 // Iterate over all libraries and setup the stub native lookup. This must be |
1092 // run after |SetupStubNativeResolversForPrecompilation| because the former | 1050 // run after |SetupStubNativeResolversForPrecompilation| because the former |
1093 // loads some libraries. | 1051 // loads some libraries. |
1094 static void SetupStubNativeResolvers() { | 1052 static void SetupStubNativeResolvers() { |
1095 Dart_Handle libraries = Dart_GetLoadedLibraries(); | 1053 Dart_Handle libraries = Dart_GetLoadedLibraries(); |
1096 intptr_t libraries_length; | 1054 intptr_t libraries_length; |
1097 Dart_ListLength(libraries, &libraries_length); | 1055 Dart_ListLength(libraries, &libraries_length); |
1098 for (intptr_t i = 0; i < libraries_length; i++) { | 1056 for (intptr_t i = 0; i < libraries_length; i++) { |
1099 Dart_Handle library = Dart_ListGetAt(libraries, i); | 1057 Dart_Handle library = Dart_ListGetAt(libraries, i); |
1100 DART_CHECK_VALID(library); | 1058 DART_CHECK_VALID(library); |
1101 Dart_NativeEntryResolver old_resolver = NULL; | 1059 Dart_NativeEntryResolver old_resolver = NULL; |
1102 Dart_GetNativeResolver(library, &old_resolver); | 1060 Dart_GetNativeResolver(library, &old_resolver); |
1103 if (old_resolver == NULL) { | 1061 if (old_resolver == NULL) { |
1104 Dart_Handle result = | 1062 Dart_Handle result = |
1105 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol); | 1063 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol); |
1106 DART_CHECK_VALID(result); | 1064 DART_CHECK_VALID(result); |
1107 } | 1065 } |
1108 } | 1066 } |
1109 } | 1067 } |
1110 | 1068 |
1111 | |
1112 static void ImportNativeEntryPointLibrariesIntoRoot( | 1069 static void ImportNativeEntryPointLibrariesIntoRoot( |
1113 const Dart_QualifiedFunctionName* entries) { | 1070 const Dart_QualifiedFunctionName* entries) { |
1114 if (entries == NULL) { | 1071 if (entries == NULL) { |
1115 return; | 1072 return; |
1116 } | 1073 } |
1117 | 1074 |
1118 size_t index = 0; | 1075 size_t index = 0; |
1119 while (true) { | 1076 while (true) { |
1120 Dart_QualifiedFunctionName entry = entries[index++]; | 1077 Dart_QualifiedFunctionName entry = entries[index++]; |
1121 if (entry.library_uri == NULL) { | 1078 if (entry.library_uri == NULL) { |
1122 // The termination sentinel has null members. | 1079 // The termination sentinel has null members. |
1123 break; | 1080 break; |
1124 } | 1081 } |
1125 Dart_Handle entry_library = | 1082 Dart_Handle entry_library = |
1126 Dart_LookupLibrary(Dart_NewStringFromCString(entry.library_uri)); | 1083 Dart_LookupLibrary(Dart_NewStringFromCString(entry.library_uri)); |
1127 DART_CHECK_VALID(entry_library); | 1084 DART_CHECK_VALID(entry_library); |
1128 Dart_Handle import_result = Dart_LibraryImportLibrary( | 1085 Dart_Handle import_result = Dart_LibraryImportLibrary( |
1129 entry_library, Dart_RootLibrary(), Dart_EmptyString()); | 1086 entry_library, Dart_RootLibrary(), Dart_EmptyString()); |
1130 DART_CHECK_VALID(import_result); | 1087 DART_CHECK_VALID(import_result); |
1131 } | 1088 } |
1132 } | 1089 } |
1133 | 1090 |
1134 | |
1135 static void SetupStubNativeResolversForPrecompilation( | 1091 static void SetupStubNativeResolversForPrecompilation( |
1136 const Dart_QualifiedFunctionName* entries) { | 1092 const Dart_QualifiedFunctionName* entries) { |
1137 if (entries == NULL) { | 1093 if (entries == NULL) { |
1138 return; | 1094 return; |
1139 } | 1095 } |
1140 | 1096 |
1141 // Setup native resolvers for all libraries found in the manifest. | 1097 // Setup native resolvers for all libraries found in the manifest. |
1142 size_t index = 0; | 1098 size_t index = 0; |
1143 while (true) { | 1099 while (true) { |
1144 Dart_QualifiedFunctionName entry = entries[index++]; | 1100 Dart_QualifiedFunctionName entry = entries[index++]; |
1145 if (entry.library_uri == NULL) { | 1101 if (entry.library_uri == NULL) { |
1146 // The termination sentinel has null members. | 1102 // The termination sentinel has null members. |
1147 break; | 1103 break; |
1148 } | 1104 } |
1149 // Setup stub resolvers on loaded libraries | 1105 // Setup stub resolvers on loaded libraries |
1150 SetupStubNativeResolver(index, &entry); | 1106 SetupStubNativeResolver(index, &entry); |
1151 } | 1107 } |
1152 } | 1108 } |
1153 | 1109 |
1154 | |
1155 static void CleanupEntryPointItem(const Dart_QualifiedFunctionName* entry) { | 1110 static void CleanupEntryPointItem(const Dart_QualifiedFunctionName* entry) { |
1156 if (entry == NULL) { | 1111 if (entry == NULL) { |
1157 return; | 1112 return; |
1158 } | 1113 } |
1159 // The allocation used for these entries is zero'ed. So even in error cases, | 1114 // The allocation used for these entries is zero'ed. So even in error cases, |
1160 // references to some entries will be null. Calling this on an already cleaned | 1115 // references to some entries will be null. Calling this on an already cleaned |
1161 // up entry is programmer error. | 1116 // up entry is programmer error. |
1162 free(const_cast<char*>(entry->library_uri)); | 1117 free(const_cast<char*>(entry->library_uri)); |
1163 free(const_cast<char*>(entry->class_name)); | 1118 free(const_cast<char*>(entry->class_name)); |
1164 free(const_cast<char*>(entry->function_name)); | 1119 free(const_cast<char*>(entry->function_name)); |
1165 } | 1120 } |
1166 | 1121 |
1167 | |
1168 static void CleanupEntryPointsCollection(Dart_QualifiedFunctionName* entries) { | 1122 static void CleanupEntryPointsCollection(Dart_QualifiedFunctionName* entries) { |
1169 if (entries == NULL) { | 1123 if (entries == NULL) { |
1170 return; | 1124 return; |
1171 } | 1125 } |
1172 | 1126 |
1173 size_t index = 0; | 1127 size_t index = 0; |
1174 while (true) { | 1128 while (true) { |
1175 Dart_QualifiedFunctionName entry = entries[index++]; | 1129 Dart_QualifiedFunctionName entry = entries[index++]; |
1176 if (entry.library_uri == NULL) { | 1130 if (entry.library_uri == NULL) { |
1177 break; | 1131 break; |
1178 } | 1132 } |
1179 CleanupEntryPointItem(&entry); | 1133 CleanupEntryPointItem(&entry); |
1180 } | 1134 } |
1181 free(entries); | 1135 free(entries); |
1182 } | 1136 } |
1183 | 1137 |
1184 | |
1185 char* ParserErrorStringCreate(const char* format, ...) { | 1138 char* ParserErrorStringCreate(const char* format, ...) { |
1186 static const size_t kErrorBufferSize = 256; | 1139 static const size_t kErrorBufferSize = 256; |
1187 | 1140 |
1188 char* error_buffer = | 1141 char* error_buffer = |
1189 reinterpret_cast<char*>(calloc(kErrorBufferSize, sizeof(char))); | 1142 reinterpret_cast<char*>(calloc(kErrorBufferSize, sizeof(char))); |
1190 va_list args; | 1143 va_list args; |
1191 va_start(args, format); | 1144 va_start(args, format); |
1192 vsnprintf(error_buffer, kErrorBufferSize, format, args); | 1145 vsnprintf(error_buffer, kErrorBufferSize, format, args); |
1193 va_end(args); | 1146 va_end(args); |
1194 | 1147 |
1195 // In case of error, the buffer is released by the caller | 1148 // In case of error, the buffer is released by the caller |
1196 return error_buffer; | 1149 return error_buffer; |
1197 } | 1150 } |
1198 | 1151 |
1199 | |
1200 const char* ParseEntryNameForIndex(uint8_t index) { | 1152 const char* ParseEntryNameForIndex(uint8_t index) { |
1201 switch (index) { | 1153 switch (index) { |
1202 case 0: | 1154 case 0: |
1203 return "Library"; | 1155 return "Library"; |
1204 case 1: | 1156 case 1: |
1205 return "Class"; | 1157 return "Class"; |
1206 case 2: | 1158 case 2: |
1207 return "Function"; | 1159 return "Function"; |
1208 default: | 1160 default: |
1209 return "Unknown"; | 1161 return "Unknown"; |
1210 } | 1162 } |
1211 return NULL; | 1163 return NULL; |
1212 } | 1164 } |
1213 | 1165 |
1214 | |
1215 static bool ParseEntryPointsManifestSingleLine( | 1166 static bool ParseEntryPointsManifestSingleLine( |
1216 const char* line, | 1167 const char* line, |
1217 Dart_QualifiedFunctionName* entry, | 1168 Dart_QualifiedFunctionName* entry, |
1218 char** error) { | 1169 char** error) { |
1219 bool success = true; | 1170 bool success = true; |
1220 size_t offset = 0; | 1171 size_t offset = 0; |
1221 for (uint8_t i = 0; i < 3; i++) { | 1172 for (uint8_t i = 0; i < 3; i++) { |
1222 const char* component = strchr(line + offset, i == 2 ? '\n' : ','); | 1173 const char* component = strchr(line + offset, i == 2 ? '\n' : ','); |
1223 if (component == NULL) { | 1174 if (component == NULL) { |
1224 success = false; | 1175 success = false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 *error = ParserErrorStringCreate("Internal parser error\n"); | 1211 *error = ParserErrorStringCreate("Internal parser error\n"); |
1261 break; | 1212 break; |
1262 } | 1213 } |
1263 } | 1214 } |
1264 | 1215 |
1265 offset += chars_read + 1; | 1216 offset += chars_read + 1; |
1266 } | 1217 } |
1267 return success; | 1218 return success; |
1268 } | 1219 } |
1269 | 1220 |
1270 | |
1271 int64_t ParseEntryPointsManifestLines(FILE* file, | 1221 int64_t ParseEntryPointsManifestLines(FILE* file, |
1272 Dart_QualifiedFunctionName* collection) { | 1222 Dart_QualifiedFunctionName* collection) { |
1273 int64_t entries = 0; | 1223 int64_t entries = 0; |
1274 | 1224 |
1275 static const int kManifestMaxLineLength = 1024; | 1225 static const int kManifestMaxLineLength = 1024; |
1276 char* line = reinterpret_cast<char*>(malloc(kManifestMaxLineLength)); | 1226 char* line = reinterpret_cast<char*>(malloc(kManifestMaxLineLength)); |
1277 size_t line_number = 0; | 1227 size_t line_number = 0; |
1278 while (true) { | 1228 while (true) { |
1279 line_number++; | 1229 line_number++; |
1280 char* read_line = fgets(line, kManifestMaxLineLength, file); | 1230 char* read_line = fgets(line, kManifestMaxLineLength, file); |
(...skipping 23 matching lines...) Expand all Loading... |
1304 } | 1254 } |
1305 | 1255 |
1306 entries++; | 1256 entries++; |
1307 } | 1257 } |
1308 | 1258 |
1309 free(line); | 1259 free(line); |
1310 | 1260 |
1311 return entries; | 1261 return entries; |
1312 } | 1262 } |
1313 | 1263 |
1314 | |
1315 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFiles() { | 1264 static Dart_QualifiedFunctionName* ParseEntryPointsManifestFiles() { |
1316 // Total number of entries across all manifest files. | 1265 // Total number of entries across all manifest files. |
1317 int64_t entry_count = 0; | 1266 int64_t entry_count = 0; |
1318 | 1267 |
1319 // Parse the files once but don't store the results. This is done to first | 1268 // Parse the files once but don't store the results. This is done to first |
1320 // determine the number of entries in the manifest | 1269 // determine the number of entries in the manifest |
1321 for (intptr_t i = 0; i < entry_points_files->count(); i++) { | 1270 for (intptr_t i = 0; i < entry_points_files->count(); i++) { |
1322 const char* path = entry_points_files->GetArgument(i); | 1271 const char* path = entry_points_files->GetArgument(i); |
1323 | 1272 |
1324 FILE* file = fopen(path, "r"); | 1273 FILE* file = fopen(path, "r"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 fclose(file); | 1305 fclose(file); |
1357 } | 1306 } |
1358 | 1307 |
1359 ASSERT(parsed_entry_count == entry_count); | 1308 ASSERT(parsed_entry_count == entry_count); |
1360 | 1309 |
1361 // The entries allocation must be explicitly cleaned up via | 1310 // The entries allocation must be explicitly cleaned up via |
1362 // |CleanupEntryPointsCollection| | 1311 // |CleanupEntryPointsCollection| |
1363 return entries; | 1312 return entries; |
1364 } | 1313 } |
1365 | 1314 |
1366 | |
1367 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() { | 1315 static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() { |
1368 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles(); | 1316 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles(); |
1369 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { | 1317 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { |
1370 Log::PrintErr( | 1318 Log::PrintErr( |
1371 "Could not find native embedder entry points during precompilation\n"); | 1319 "Could not find native embedder entry points during precompilation\n"); |
1372 exit(kErrorExitCode); | 1320 exit(kErrorExitCode); |
1373 } | 1321 } |
1374 return entries; | 1322 return entries; |
1375 } | 1323 } |
1376 | 1324 |
1377 | |
1378 static void LoadCompilationTrace() { | 1325 static void LoadCompilationTrace() { |
1379 if ((load_compilation_trace_filename != NULL) && | 1326 if ((load_compilation_trace_filename != NULL) && |
1380 (snapshot_kind == kCoreJIT)) { | 1327 (snapshot_kind == kCoreJIT)) { |
1381 uint8_t* buffer = NULL; | 1328 uint8_t* buffer = NULL; |
1382 intptr_t size = 0; | 1329 intptr_t size = 0; |
1383 ReadFile(load_compilation_trace_filename, &buffer, &size); | 1330 ReadFile(load_compilation_trace_filename, &buffer, &size); |
1384 Dart_Handle result = Dart_LoadCompilationTrace(buffer, size); | 1331 Dart_Handle result = Dart_LoadCompilationTrace(buffer, size); |
1385 CHECK_RESULT(result); | 1332 CHECK_RESULT(result); |
1386 } | 1333 } |
1387 } | 1334 } |
1388 | 1335 |
1389 | |
1390 static void CreateAndWriteCoreSnapshot() { | 1336 static void CreateAndWriteCoreSnapshot() { |
1391 ASSERT(snapshot_kind == kCore); | 1337 ASSERT(snapshot_kind == kCore); |
1392 ASSERT(vm_snapshot_data_filename != NULL); | 1338 ASSERT(vm_snapshot_data_filename != NULL); |
1393 ASSERT(isolate_snapshot_data_filename != NULL); | 1339 ASSERT(isolate_snapshot_data_filename != NULL); |
1394 | 1340 |
1395 Dart_Handle result; | 1341 Dart_Handle result; |
1396 uint8_t* vm_snapshot_data_buffer = NULL; | 1342 uint8_t* vm_snapshot_data_buffer = NULL; |
1397 intptr_t vm_snapshot_data_size = 0; | 1343 intptr_t vm_snapshot_data_size = 0; |
1398 uint8_t* isolate_snapshot_data_buffer = NULL; | 1344 uint8_t* isolate_snapshot_data_buffer = NULL; |
1399 intptr_t isolate_snapshot_data_size = 0; | 1345 intptr_t isolate_snapshot_data_size = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
1411 if (vm_snapshot_instructions_filename != NULL) { | 1357 if (vm_snapshot_instructions_filename != NULL) { |
1412 WriteFile(vm_snapshot_instructions_filename, NULL, 0); | 1358 WriteFile(vm_snapshot_instructions_filename, NULL, 0); |
1413 } | 1359 } |
1414 WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer, | 1360 WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer, |
1415 isolate_snapshot_data_size); | 1361 isolate_snapshot_data_size); |
1416 if (isolate_snapshot_instructions_filename != NULL) { | 1362 if (isolate_snapshot_instructions_filename != NULL) { |
1417 WriteFile(isolate_snapshot_instructions_filename, NULL, 0); | 1363 WriteFile(isolate_snapshot_instructions_filename, NULL, 0); |
1418 } | 1364 } |
1419 } | 1365 } |
1420 | 1366 |
1421 | |
1422 static void CreateAndWriteCoreJITSnapshot() { | 1367 static void CreateAndWriteCoreJITSnapshot() { |
1423 ASSERT(snapshot_kind == kCoreJIT); | 1368 ASSERT(snapshot_kind == kCoreJIT); |
1424 ASSERT(vm_snapshot_data_filename != NULL); | 1369 ASSERT(vm_snapshot_data_filename != NULL); |
1425 ASSERT(vm_snapshot_instructions_filename != NULL); | 1370 ASSERT(vm_snapshot_instructions_filename != NULL); |
1426 ASSERT(isolate_snapshot_data_filename != NULL); | 1371 ASSERT(isolate_snapshot_data_filename != NULL); |
1427 ASSERT(isolate_snapshot_instructions_filename != NULL); | 1372 ASSERT(isolate_snapshot_instructions_filename != NULL); |
1428 | 1373 |
1429 Dart_Handle result; | 1374 Dart_Handle result; |
1430 uint8_t* vm_snapshot_data_buffer = NULL; | 1375 uint8_t* vm_snapshot_data_buffer = NULL; |
1431 intptr_t vm_snapshot_data_size = 0; | 1376 intptr_t vm_snapshot_data_size = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
1451 vm_snapshot_data_size); | 1396 vm_snapshot_data_size); |
1452 WriteFile(vm_snapshot_instructions_filename, vm_snapshot_instructions_buffer, | 1397 WriteFile(vm_snapshot_instructions_filename, vm_snapshot_instructions_buffer, |
1453 vm_snapshot_instructions_size); | 1398 vm_snapshot_instructions_size); |
1454 WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer, | 1399 WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer, |
1455 isolate_snapshot_data_size); | 1400 isolate_snapshot_data_size); |
1456 WriteFile(isolate_snapshot_instructions_filename, | 1401 WriteFile(isolate_snapshot_instructions_filename, |
1457 isolate_snapshot_instructions_buffer, | 1402 isolate_snapshot_instructions_buffer, |
1458 isolate_snapshot_instructions_size); | 1403 isolate_snapshot_instructions_size); |
1459 } | 1404 } |
1460 | 1405 |
1461 | |
1462 static void CreateAndWriteScriptSnapshot() { | 1406 static void CreateAndWriteScriptSnapshot() { |
1463 ASSERT(snapshot_kind == kScript); | 1407 ASSERT(snapshot_kind == kScript); |
1464 ASSERT(script_snapshot_filename != NULL); | 1408 ASSERT(script_snapshot_filename != NULL); |
1465 | 1409 |
1466 // First create a snapshot. | 1410 // First create a snapshot. |
1467 uint8_t* buffer = NULL; | 1411 uint8_t* buffer = NULL; |
1468 intptr_t size = 0; | 1412 intptr_t size = 0; |
1469 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1413 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
1470 CHECK_RESULT(result); | 1414 CHECK_RESULT(result); |
1471 | 1415 |
1472 // Now write it out to the specified file. | 1416 // Now write it out to the specified file. |
1473 WriteFile(script_snapshot_filename, buffer, size); | 1417 WriteFile(script_snapshot_filename, buffer, size); |
1474 } | 1418 } |
1475 | 1419 |
1476 | |
1477 static void CreateAndWritePrecompiledSnapshot( | 1420 static void CreateAndWritePrecompiledSnapshot( |
1478 Dart_QualifiedFunctionName* standalone_entry_points) { | 1421 Dart_QualifiedFunctionName* standalone_entry_points) { |
1479 ASSERT(IsSnapshottingForPrecompilation()); | 1422 ASSERT(IsSnapshottingForPrecompilation()); |
1480 Dart_Handle result; | 1423 Dart_Handle result; |
1481 | 1424 |
1482 // Precompile with specified embedder entry points | 1425 // Precompile with specified embedder entry points |
1483 result = Dart_Precompile(standalone_entry_points, NULL, 0); | 1426 result = Dart_Precompile(standalone_entry_points, NULL, 0); |
1484 CHECK_RESULT(result); | 1427 CHECK_RESULT(result); |
1485 | 1428 |
1486 // Create a precompiled snapshot. | 1429 // Create a precompiled snapshot. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 WriteFile(vm_snapshot_instructions_filename, | 1462 WriteFile(vm_snapshot_instructions_filename, |
1520 vm_snapshot_instructions_buffer, vm_snapshot_instructions_size); | 1463 vm_snapshot_instructions_buffer, vm_snapshot_instructions_size); |
1521 WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer, | 1464 WriteFile(isolate_snapshot_data_filename, isolate_snapshot_data_buffer, |
1522 isolate_snapshot_data_size); | 1465 isolate_snapshot_data_size); |
1523 WriteFile(isolate_snapshot_instructions_filename, | 1466 WriteFile(isolate_snapshot_instructions_filename, |
1524 isolate_snapshot_instructions_buffer, | 1467 isolate_snapshot_instructions_buffer, |
1525 isolate_snapshot_instructions_size); | 1468 isolate_snapshot_instructions_size); |
1526 } | 1469 } |
1527 } | 1470 } |
1528 | 1471 |
1529 | |
1530 static void SetupForUriResolution() { | 1472 static void SetupForUriResolution() { |
1531 // Set up the library tag handler for this isolate. | 1473 // Set up the library tag handler for this isolate. |
1532 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 1474 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
1533 if (Dart_IsError(result)) { | 1475 if (Dart_IsError(result)) { |
1534 Log::PrintErr("%s\n", Dart_GetError(result)); | 1476 Log::PrintErr("%s\n", Dart_GetError(result)); |
1535 Dart_ExitScope(); | 1477 Dart_ExitScope(); |
1536 Dart_ShutdownIsolate(); | 1478 Dart_ShutdownIsolate(); |
1537 exit(kErrorExitCode); | 1479 exit(kErrorExitCode); |
1538 } | 1480 } |
1539 // This is a generic dart snapshot which needs builtin library setup. | 1481 // This is a generic dart snapshot which needs builtin library setup. |
1540 Dart_Handle library = | 1482 Dart_Handle library = |
1541 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | 1483 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); |
1542 CHECK_RESULT(library); | 1484 CHECK_RESULT(library); |
1543 } | 1485 } |
1544 | 1486 |
1545 | |
1546 static void SetupForGenericSnapshotCreation() { | 1487 static void SetupForGenericSnapshotCreation() { |
1547 SetupForUriResolution(); | 1488 SetupForUriResolution(); |
1548 | 1489 |
1549 Dart_Handle library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); | 1490 Dart_Handle library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); |
1550 CHECK_RESULT(library); | 1491 CHECK_RESULT(library); |
1551 Dart_Handle result = Dart_FinalizeLoading(false); | 1492 Dart_Handle result = Dart_FinalizeLoading(false); |
1552 if (Dart_IsError(result)) { | 1493 if (Dart_IsError(result)) { |
1553 const char* err_msg = Dart_GetError(library); | 1494 const char* err_msg = Dart_GetError(library); |
1554 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); | 1495 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); |
1555 Dart_ExitScope(); | 1496 Dart_ExitScope(); |
1556 Dart_ShutdownIsolate(); | 1497 Dart_ShutdownIsolate(); |
1557 exit(kErrorExitCode); | 1498 exit(kErrorExitCode); |
1558 } | 1499 } |
1559 } | 1500 } |
1560 | 1501 |
1561 | |
1562 static Dart_Isolate CreateServiceIsolate(const char* script_uri, | 1502 static Dart_Isolate CreateServiceIsolate(const char* script_uri, |
1563 const char* main, | 1503 const char* main, |
1564 const char* package_root, | 1504 const char* package_root, |
1565 const char* package_config, | 1505 const char* package_config, |
1566 Dart_IsolateFlags* flags, | 1506 Dart_IsolateFlags* flags, |
1567 void* data, | 1507 void* data, |
1568 char** error) { | 1508 char** error) { |
1569 IsolateData* isolate_data = | 1509 IsolateData* isolate_data = |
1570 new IsolateData(script_uri, package_root, package_config, NULL); | 1510 new IsolateData(script_uri, package_root, package_config, NULL); |
1571 Dart_Isolate isolate = NULL; | 1511 Dart_Isolate isolate = NULL; |
(...skipping 26 matching lines...) Expand all Loading... |
1598 false /* server dev mode */, | 1538 false /* server dev mode */, |
1599 false /* trace_loading */)) { | 1539 false /* trace_loading */)) { |
1600 *error = strdup(VmService::GetErrorMessage()); | 1540 *error = strdup(VmService::GetErrorMessage()); |
1601 return NULL; | 1541 return NULL; |
1602 } | 1542 } |
1603 Dart_ExitScope(); | 1543 Dart_ExitScope(); |
1604 Dart_ExitIsolate(); | 1544 Dart_ExitIsolate(); |
1605 return isolate; | 1545 return isolate; |
1606 } | 1546 } |
1607 | 1547 |
1608 | |
1609 static MappedMemory* MapFile(const char* filename, | 1548 static MappedMemory* MapFile(const char* filename, |
1610 File::MapType type, | 1549 File::MapType type, |
1611 const uint8_t** buffer) { | 1550 const uint8_t** buffer) { |
1612 File* file = File::Open(filename, File::kRead); | 1551 File* file = File::Open(filename, File::kRead); |
1613 if (file == NULL) { | 1552 if (file == NULL) { |
1614 Log::PrintErr("Failed to open: %s\n", filename); | 1553 Log::PrintErr("Failed to open: %s\n", filename); |
1615 exit(kErrorExitCode); | 1554 exit(kErrorExitCode); |
1616 } | 1555 } |
1617 intptr_t length = file->Length(); | 1556 intptr_t length = file->Length(); |
1618 if (length == 0) { | 1557 if (length == 0) { |
1619 // Can't map an empty file. | 1558 // Can't map an empty file. |
1620 *buffer = NULL; | 1559 *buffer = NULL; |
1621 return NULL; | 1560 return NULL; |
1622 } | 1561 } |
1623 MappedMemory* mapping = file->Map(type, 0, length); | 1562 MappedMemory* mapping = file->Map(type, 0, length); |
1624 if (mapping == NULL) { | 1563 if (mapping == NULL) { |
1625 Log::PrintErr("Failed to read: %s\n", filename); | 1564 Log::PrintErr("Failed to read: %s\n", filename); |
1626 exit(kErrorExitCode); | 1565 exit(kErrorExitCode); |
1627 } | 1566 } |
1628 file->Release(); | 1567 file->Release(); |
1629 *buffer = reinterpret_cast<const uint8_t*>(mapping->address()); | 1568 *buffer = reinterpret_cast<const uint8_t*>(mapping->address()); |
1630 return mapping; | 1569 return mapping; |
1631 } | 1570 } |
1632 | 1571 |
1633 | |
1634 int main(int argc, char** argv) { | 1572 int main(int argc, char** argv) { |
1635 const int EXTRA_VM_ARGUMENTS = 2; | 1573 const int EXTRA_VM_ARGUMENTS = 2; |
1636 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1574 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
1637 | 1575 |
1638 // Initialize the URL mapping array. | 1576 // Initialize the URL mapping array. |
1639 CommandLineOptions cmdline_url_mapping(argc); | 1577 CommandLineOptions cmdline_url_mapping(argc); |
1640 DartUtils::url_mapping = &cmdline_url_mapping; | 1578 DartUtils::url_mapping = &cmdline_url_mapping; |
1641 | 1579 |
1642 // Initialize the entrypoints array. | 1580 // Initialize the entrypoints array. |
1643 CommandLineOptions entry_points_files_array(argc); | 1581 CommandLineOptions entry_points_files_array(argc); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 delete mapped_isolate_snapshot_instructions; | 1835 delete mapped_isolate_snapshot_instructions; |
1898 return 0; | 1836 return 0; |
1899 } | 1837 } |
1900 | 1838 |
1901 } // namespace bin | 1839 } // namespace bin |
1902 } // namespace dart | 1840 } // namespace dart |
1903 | 1841 |
1904 int main(int argc, char** argv) { | 1842 int main(int argc, char** argv) { |
1905 return dart::bin::main(argc, argv); | 1843 return dart::bin::main(argc, argv); |
1906 } | 1844 } |
OLD | NEW |