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 <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (!file->WriteFully(buffer, size)) { | 164 if (!file->WriteFully(buffer, size)) { |
165 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | 165 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); |
166 } | 166 } |
167 delete file; | 167 delete file; |
168 } | 168 } |
169 | 169 |
170 | 170 |
171 class UriResolverIsolateScope { | 171 class UriResolverIsolateScope { |
172 public: | 172 public: |
173 UriResolverIsolateScope() { | 173 UriResolverIsolateScope() { |
174 ASSERT(isolate != NULL); | 174 ASSERT(isolate != ILLEGAL_ISOLATE); |
175 snapshotted_isolate_ = Dart_CurrentIsolate(); | 175 snapshotted_isolate_ = Dart_CurrentIsolate(); |
176 Dart_ExitIsolate(); | 176 Dart_ExitIsolate(); |
177 Dart_EnterIsolate(isolate); | 177 Dart_EnterIsolate(isolate); |
178 Dart_EnterScope(); | 178 Dart_EnterScope(); |
179 } | 179 } |
180 | 180 |
181 ~UriResolverIsolateScope() { | 181 ~UriResolverIsolateScope() { |
182 ASSERT(snapshotted_isolate_ != NULL); | 182 ASSERT(snapshotted_isolate_ != ILLEGAL_ISOLATE); |
183 Dart_ExitScope(); | 183 Dart_ExitScope(); |
184 Dart_ExitIsolate(); | 184 Dart_ExitIsolate(); |
185 Dart_EnterIsolate(snapshotted_isolate_); | 185 Dart_EnterIsolate(snapshotted_isolate_); |
186 } | 186 } |
187 | 187 |
188 static Dart_Isolate isolate; | 188 static Dart_Isolate isolate; |
189 | 189 |
190 private: | 190 private: |
191 Dart_Isolate snapshotted_isolate_; | 191 Dart_Isolate snapshotted_isolate_; |
192 | 192 |
193 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); | 193 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); |
194 }; | 194 }; |
195 | 195 |
196 Dart_Isolate UriResolverIsolateScope::isolate = NULL; | 196 Dart_Isolate UriResolverIsolateScope::isolate = ILLEGAL_ISOLATE; |
197 | 197 |
198 | 198 |
199 static Dart_Handle ResolveScriptUri(const char* script_uri) { | 199 static Dart_Handle ResolveScriptUri(const char* script_uri) { |
200 bool failed = false; | 200 bool failed = false; |
201 char* result_string = NULL; | 201 char* result_string = NULL; |
202 | 202 |
203 { | 203 { |
204 UriResolverIsolateScope scope; | 204 UriResolverIsolateScope scope; |
205 | 205 |
206 // Run DartUtils::ResolveScriptUri in context of uri resolver isolate. | 206 // Run DartUtils::ResolveScriptUri in context of uri resolver isolate. |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 DartUtils::ReadFile, | 544 DartUtils::ReadFile, |
545 DartUtils::WriteFile, | 545 DartUtils::WriteFile, |
546 DartUtils::CloseFile, | 546 DartUtils::CloseFile, |
547 DartUtils::EntropySource)) { | 547 DartUtils::EntropySource)) { |
548 Log::PrintErr("VM initialization failed\n"); | 548 Log::PrintErr("VM initialization failed\n"); |
549 return 255; | 549 return 255; |
550 } | 550 } |
551 | 551 |
552 char* error; | 552 char* error; |
553 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); | 553 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); |
554 if (isolate == NULL) { | 554 if (isolate == ILLEGAL_ISOLATE) { |
555 Log::PrintErr("Error: %s", error); | 555 Log::PrintErr("Error: %s", error); |
556 free(error); | 556 free(error); |
557 exit(255); | 557 exit(255); |
558 } | 558 } |
559 | 559 |
560 Dart_Handle result; | 560 Dart_Handle result; |
561 Dart_Handle library; | 561 Dart_Handle library; |
562 Dart_EnterScope(); | 562 Dart_EnterScope(); |
563 | 563 |
564 ASSERT(vm_isolate_snapshot_filename != NULL); | 564 ASSERT(vm_isolate_snapshot_filename != NULL); |
(...skipping 21 matching lines...) Expand all Loading... |
586 result = | 586 result = |
587 DartUtils::PrepareForScriptLoading(package_root, false, builtin_lib); | 587 DartUtils::PrepareForScriptLoading(package_root, false, builtin_lib); |
588 CHECK_RESULT(result); | 588 CHECK_RESULT(result); |
589 Dart_ExitScope(); | 589 Dart_ExitScope(); |
590 Dart_ExitIsolate(); | 590 Dart_ExitIsolate(); |
591 | 591 |
592 UriResolverIsolateScope::isolate = isolate; | 592 UriResolverIsolateScope::isolate = isolate; |
593 | 593 |
594 // Now we create an isolate into which we load all the code that needs to | 594 // Now we create an isolate into which we load all the code that needs to |
595 // be in the snapshot. | 595 // be in the snapshot. |
596 if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error) == NULL) { | 596 if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error) == ILLEGAL_ISOLATE) { |
597 fprintf(stderr, "%s", error); | 597 fprintf(stderr, "%s", error); |
598 free(error); | 598 free(error); |
599 exit(255); | 599 exit(255); |
600 } | 600 } |
601 Dart_EnterScope(); | 601 Dart_EnterScope(); |
602 | 602 |
603 // Set up the library tag handler in such a manner that it will use the | 603 // Set up the library tag handler in such a manner that it will use the |
604 // URL mapping specified on the command line to load the libraries. | 604 // URL mapping specified on the command line to load the libraries. |
605 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 605 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
606 CHECK_RESULT(result); | 606 CHECK_RESULT(result); |
(...skipping 13 matching lines...) Expand all Loading... |
620 } | 620 } |
621 return 0; | 621 return 0; |
622 } | 622 } |
623 | 623 |
624 } // namespace bin | 624 } // namespace bin |
625 } // namespace dart | 625 } // namespace dart |
626 | 626 |
627 int main(int argc, char** argv) { | 627 int main(int argc, char** argv) { |
628 return dart::bin::main(argc, argv); | 628 return dart::bin::main(argc, argv); |
629 } | 629 } |
OLD | NEW |