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

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

Issue 2485993002: VM: Support bootstrapping core libraries from Kernel binaries instead of source. (Closed)
Patch Set: Done Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 #else 792 #else
793 // Always create the service isolate in DEBUG and RELEASE modes for profiling, 793 // Always create the service isolate in DEBUG and RELEASE modes for profiling,
794 // even if we don't need it for loading. 794 // even if we don't need it for loading.
795 const bool run_service_isolate = true; 795 const bool run_service_isolate = true;
796 #endif // PRODUCT 796 #endif // PRODUCT
797 if (!run_service_isolate && 797 if (!run_service_isolate &&
798 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { 798 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) {
799 return NULL; 799 return NULL;
800 } 800 }
801 801
802 // If the script is a Kernel binary, then we will try to bootstrap from the
803 // script.
804 const uint8_t* kernel_file = NULL;
805 intptr_t kernel_length = -1;
806 const bool is_kernel =
807 !run_app_snapshot &&
808 TryReadKernel(script_uri, &kernel_file, &kernel_length);
809
802 IsolateData* isolate_data = 810 IsolateData* isolate_data =
803 new IsolateData(script_uri, package_root, packages_config); 811 new IsolateData(script_uri, package_root, packages_config);
804 Dart_Isolate isolate = Dart_CreateIsolate( 812 Dart_Isolate isolate =
805 script_uri, main, isolate_snapshot_buffer, flags, isolate_data, error); 813 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_file,
814 kernel_length, flags,
815 isolate_data, error)
816 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_buffer,
817 flags, isolate_data, error);
818 if (is_kernel) {
819 free(const_cast<uint8_t*>(kernel_file));
820 }
821
806 if (isolate == NULL) { 822 if (isolate == NULL) {
807 delete isolate_data; 823 delete isolate_data;
808 return NULL; 824 return NULL;
809 } 825 }
810 826
811 Dart_EnterScope(); 827 Dart_EnterScope();
812 828
813 if (isolate_snapshot_buffer != NULL) { 829 // Set up the library tag handler for this isolate.
830 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
831 CHECK_RESULT(result);
832
833 if (is_kernel) {
834 // TODO(27590): We should not read the kernel file again!
835 if (!TryReadKernel(script_uri, &kernel_file, &kernel_length)) {
836 FATAL("Failed to read kernel second time");
837 }
838 Dart_Handle result = Dart_LoadKernel(kernel_file, kernel_length);
siva 2016/11/16 05:49:34 The TODO says do not read the kernel file again, d
Vyacheslav Egorov (Google) 2016/11/16 12:47:46 There is a difference between snapshots we have an
839 free(const_cast<uint8_t*>(kernel_file));
840 CHECK_RESULT(result);
841 }
842 if (is_kernel || (isolate_snapshot_buffer != NULL)) {
814 // Setup the native resolver as the snapshot does not carry it. 843 // Setup the native resolver as the snapshot does not carry it.
815 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 844 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
816 Builtin::SetNativeResolver(Builtin::kIOLibrary); 845 Builtin::SetNativeResolver(Builtin::kIOLibrary);
817 } 846 }
818 if (run_app_snapshot) { 847 if (run_app_snapshot) {
819 Dart_Handle result = Loader::ReloadNativeExtensions(); 848 Dart_Handle result = Loader::ReloadNativeExtensions();
820 CHECK_RESULT(result); 849 CHECK_RESULT(result);
821 } 850 }
822 851
823 // Set up the library tag handler for this isolate.
824 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler);
825 CHECK_RESULT(result);
826
827 if (Dart_IsServiceIsolate(isolate)) { 852 if (Dart_IsServiceIsolate(isolate)) {
828 // If this is the service isolate, load embedder specific bits and return. 853 // If this is the service isolate, load embedder specific bits and return.
829 bool skip_library_load = run_app_snapshot; 854 bool skip_library_load = run_app_snapshot;
830 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, 855 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port,
831 skip_library_load, vm_service_dev_mode)) { 856 skip_library_load, vm_service_dev_mode)) {
832 *error = strdup(VmService::GetErrorMessage()); 857 *error = strdup(VmService::GetErrorMessage());
833 return NULL; 858 return NULL;
834 } 859 }
835 if (compile_all) { 860 if (compile_all) {
836 result = Dart_CompileAll(); 861 result = Dart_CompileAll();
(...skipping 28 matching lines...) Expand all
865 890
866 if (run_app_snapshot) { 891 if (run_app_snapshot) {
867 result = DartUtils::SetupIOLibrary(script_uri); 892 result = DartUtils::SetupIOLibrary(script_uri);
868 CHECK_RESULT(result); 893 CHECK_RESULT(result);
869 Loader::InitForSnapshot(script_uri); 894 Loader::InitForSnapshot(script_uri);
870 } else { 895 } else {
871 // Load the specified application script into the newly created isolate. 896 // Load the specified application script into the newly created isolate.
872 Dart_Handle uri = 897 Dart_Handle uri =
873 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); 898 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri));
874 CHECK_RESULT(uri); 899 CHECK_RESULT(uri);
875 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); 900 if (!is_kernel) {
876 CHECK_RESULT(result); 901 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri);
902 CHECK_RESULT(result);
903 }
877 904
878 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), 905 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(),
879 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0, 906 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0,
880 NULL, NULL); 907 NULL, NULL);
881 908
882 result = DartUtils::SetupIOLibrary(script_uri); 909 result = DartUtils::SetupIOLibrary(script_uri);
883 CHECK_RESULT(result); 910 CHECK_RESULT(result);
884 } 911 }
885 912
886 // Make the isolate runnable so that it is ready to handle messages. 913 // Make the isolate runnable so that it is ready to handle messages.
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 Platform::Exit(Process::GlobalExitCode()); 1945 Platform::Exit(Process::GlobalExitCode());
1919 } 1946 }
1920 1947
1921 } // namespace bin 1948 } // namespace bin
1922 } // namespace dart 1949 } // namespace dart
1923 1950
1924 int main(int argc, char** argv) { 1951 int main(int argc, char** argv) {
1925 dart::bin::main(argc, argv); 1952 dart::bin::main(argc, argv);
1926 UNREACHABLE(); 1953 UNREACHABLE();
1927 } 1954 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698