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

Side by Side Diff: runtime/bin/gen_snapshot.cc

Issue 2518233003: Wire up the stub native resolver for all libraries in gen_snapshot (Closed)
Patch Set: rmacnak in person review Created 4 years 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
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/vm/dart_api_impl.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/eventhandler.h" 16 #include "bin/eventhandler.h"
17 #include "bin/file.h" 17 #include "bin/file.h"
18 #include "bin/loader.h" 18 #include "bin/loader.h"
19 #include "bin/log.h" 19 #include "bin/log.h"
20 #include "bin/thread.h" 20 #include "bin/thread.h"
21 #include "bin/utils.h" 21 #include "bin/utils.h"
22 #include "bin/vmservice_impl.h" 22 #include "bin/vmservice_impl.h"
23 23
24 #include "include/dart_api.h" 24 #include "include/dart_api.h"
25 #include "include/dart_tools_api.h"
25 26
26 #include "platform/hashmap.h" 27 #include "platform/hashmap.h"
27 #include "platform/globals.h" 28 #include "platform/globals.h"
28 29
29 namespace dart { 30 namespace dart {
30 namespace bin { 31 namespace bin {
31 32
32 // Exit code indicating an API error. 33 // Exit code indicating an API error.
33 static const int kApiErrorExitCode = 253; 34 static const int kApiErrorExitCode = 253;
34 // Exit code indicating a compilation error. 35 // Exit code indicating a compilation error.
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 678 }
678 ASSERT(Dart_IsLibrary(library)); 679 ASSERT(Dart_IsLibrary(library));
679 } 680 }
680 681
681 682
682 static const char StubNativeFunctionName[] = "StubNativeFunction"; 683 static const char StubNativeFunctionName[] = "StubNativeFunction";
683 684
684 685
685 void StubNativeFunction(Dart_NativeArguments arguments) { 686 void StubNativeFunction(Dart_NativeArguments arguments) {
686 // This is a stub function for the resolver 687 // This is a stub function for the resolver
687 UNREACHABLE(); 688 Dart_SetReturnValue(
689 arguments, Dart_NewApiError("<EMBEDDER DID NOT SETUP NATIVE RESOLVER>"));
688 } 690 }
689 691
690 692
691 static Dart_NativeFunction StubNativeLookup(Dart_Handle name, 693 static Dart_NativeFunction StubNativeLookup(Dart_Handle name,
692 int argument_count, 694 int argument_count,
693 bool* auto_setup_scope) { 695 bool* auto_setup_scope) {
694 return &StubNativeFunction; 696 return &StubNativeFunction;
695 } 697 }
696 698
697 699
(...skipping 30 matching lines...) Expand all
728 library = Dart_LookupLibrary(library_string); 730 library = Dart_LookupLibrary(library_string);
729 } 731 }
730 732
731 DART_CHECK_VALID(library); 733 DART_CHECK_VALID(library);
732 Dart_Handle result = 734 Dart_Handle result =
733 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol); 735 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol);
734 DART_CHECK_VALID(result); 736 DART_CHECK_VALID(result);
735 } 737 }
736 738
737 739
740 // Iterate over all libraries and setup the stub native lookup. This must be
741 // run after |SetupStubNativeResolversForPrecompilation| because the former
742 // loads some libraries.
743 static void SetupStubNativeResolvers() {
744 Dart_Handle library_ids = Dart_GetLibraryIds();
745 intptr_t library_ids_length;
746 Dart_ListLength(library_ids, &library_ids_length);
747 for (intptr_t i = 0; i < library_ids_length; i++) {
748 Dart_Handle library_id_handle = Dart_ListGetAt(library_ids, i);
749 DART_CHECK_VALID(library_id_handle);
750 int64_t library_id;
751 Dart_IntegerToInt64(library_id_handle, &library_id);
752 Dart_Handle library = Dart_GetLibraryFromId(library_id);
753 DART_CHECK_VALID(library);
754 Dart_NativeEntryResolver old_resolver = NULL;
755 Dart_GetNativeResolver(library, &old_resolver);
756 if (old_resolver == NULL) {
757 Dart_Handle result =
758 Dart_SetNativeResolver(library, &StubNativeLookup, &StubNativeSymbol);
759 DART_CHECK_VALID(result);
760 }
761 }
762 }
763
764
738 static void ImportNativeEntryPointLibrariesIntoRoot( 765 static void ImportNativeEntryPointLibrariesIntoRoot(
739 const Dart_QualifiedFunctionName* entries) { 766 const Dart_QualifiedFunctionName* entries) {
740 if (entries == NULL) { 767 if (entries == NULL) {
741 return; 768 return;
742 } 769 }
743 770
744 size_t index = 0; 771 size_t index = 0;
745 while (true) { 772 while (true) {
746 Dart_QualifiedFunctionName entry = entries[index++]; 773 Dart_QualifiedFunctionName entry = entries[index++];
747 if (entry.library_uri == NULL) { 774 if (entry.library_uri == NULL) {
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR"); 1325 if (Dart_IsError(library)) FATAL("Failed to load app from Kernel IR");
1299 } else { 1326 } else {
1300 // Set up the library tag handler in such a manner that it will use the 1327 // Set up the library tag handler in such a manner that it will use the
1301 // URL mapping specified on the command line to load the libraries. 1328 // URL mapping specified on the command line to load the libraries.
1302 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); 1329 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler);
1303 CHECK_RESULT(result); 1330 CHECK_RESULT(result);
1304 } 1331 }
1305 1332
1306 SetupStubNativeResolversForPrecompilation(entry_points); 1333 SetupStubNativeResolversForPrecompilation(entry_points);
1307 1334
1335 SetupStubNativeResolvers();
1336
1308 if (!is_kernel_file) { 1337 if (!is_kernel_file) {
1309 // Load the specified script. 1338 // Load the specified script.
1310 library = LoadSnapshotCreationScript(app_script_name); 1339 library = LoadSnapshotCreationScript(app_script_name);
1311 VerifyLoaded(library); 1340 VerifyLoaded(library);
1312 1341
1313 ImportNativeEntryPointLibrariesIntoRoot(entry_points); 1342 ImportNativeEntryPointLibrariesIntoRoot(entry_points);
1314 } 1343 }
1315 1344
1316 // Ensure that we mark all libraries as loaded. 1345 // Ensure that we mark all libraries as loaded.
1317 result = Dart_FinalizeLoading(false); 1346 result = Dart_FinalizeLoading(false);
(...skipping 21 matching lines...) Expand all
1339 EventHandler::Stop(); 1368 EventHandler::Stop();
1340 return 0; 1369 return 0;
1341 } 1370 }
1342 1371
1343 } // namespace bin 1372 } // namespace bin
1344 } // namespace dart 1373 } // namespace dart
1345 1374
1346 int main(int argc, char** argv) { 1375 int main(int argc, char** argv) {
1347 return dart::bin::main(argc, argv); 1376 return dart::bin::main(argc, argv);
1348 } 1377 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | runtime/vm/dart_api_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698