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

Side by Side Diff: runtime/vm/bootstrap_nocore.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 "vm/bootstrap.h" 5 #include "vm/bootstrap.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h"
11 #include "vm/kernel_reader.h"
9 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/object_store.h"
10 14
11 namespace dart { 15 namespace dart {
12 16
17 #define MAKE_PROPERTIES(CamelName, hacker_name) \
18 { ObjectStore::k##CamelName, "dart:" #hacker_name },
13 19
14 RawError* Bootstrap::LoadandCompileScripts() { 20
15 UNREACHABLE(); 21 struct bootstrap_lib_props {
22 ObjectStore::BootstrapLibraryId index_;
23 const char* uri_;
24 };
25
26
27 static bootstrap_lib_props bootstrap_libraries[] = {
28 FOR_EACH_BOOTSTRAP_LIBRARY(MAKE_PROPERTIES)
29 };
30
31
32 static const intptr_t bootstrap_library_count = ARRAY_SIZE(bootstrap_libraries);
33
34
35 void Finish(Thread* thread, bool from_kernel) {
36 Bootstrap::SetupNativeResolver();
37 ClassFinalizer::ProcessPendingClasses(from_kernel);
38
39 // Eagerly compile the _Closure class as it is the class of all closure
40 // instances. This allows us to just finalize function types without going
41 // through the hoops of trying to compile their scope class.
42 ObjectStore* object_store = thread->isolate()->object_store();
43 Class& cls = Class::Handle(thread->zone(), object_store->closure_class());
44 Compiler::CompileClass(cls);
45 // Eagerly compile Bool class, bool constants are used from within compiler.
46 cls = object_store->bool_class();
47 Compiler::CompileClass(cls);
48 }
49
50
51 RawError* BootstrapFromKernel(Thread* thread,
52 const uint8_t* buffer,
53 intptr_t buffer_length) {
54 Zone* zone = thread->zone();
55 kernel::Program* program =
56 ReadPrecompiledKernelFromBuffer(buffer, buffer_length);
57 if (program == NULL) {
58 const String& message =
59 String::Handle(zone, String::New("Failed to read Kernel file"));
60 return ApiError::New(message);
61 }
62
63 Isolate* isolate = thread->isolate();
64 // Mark the already-pending classes. This mark bit will be used to avoid
65 // adding classes to the list more than once.
66 GrowableObjectArray& pending_classes = GrowableObjectArray::Handle(
67 zone, isolate->object_store()->pending_classes());
68 dart::Class& pending = dart::Class::Handle(zone);
69 for (intptr_t i = 0; i < pending_classes.Length(); ++i) {
70 pending ^= pending_classes.At(i);
71 pending.set_is_marked_for_parsing();
72 }
73
74 Library& library = Library::Handle(zone);
75 String& dart_name = String::Handle(zone);
76 String& kernel_name = String::Handle(zone);
77 kernel::KernelReader reader(NULL, -1, true);
78 for (intptr_t i = 0; i < bootstrap_library_count; ++i) {
79 ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index_;
80 library = isolate->object_store()->bootstrap_library(id);
81 dart_name = library.url();
82 for (intptr_t j = 0; j < program->libraries().length(); ++j) {
83 kernel::Library* kernel_library = program->libraries()[j];
84 kernel::String* uri = kernel_library->import_uri();
85 kernel_name = Symbols::FromUTF8(thread, uri->buffer(), uri->size());
86 if (kernel_name.Equals(dart_name)) {
87 reader.ReadLibrary(kernel_library);
88 library.SetLoaded();
89 break;
90 }
91 }
92 }
93
94 Finish(thread, true);
16 return Error::null(); 95 return Error::null();
17 } 96 }
18 97
98
99 RawError* Bootstrap::DoBootstrapping(const uint8_t* kernel_buffer,
100 intptr_t kernel_buffer_length) {
101 Thread* thread = Thread::Current();
102 Isolate* isolate = thread->isolate();
103 Zone* zone = thread->zone();
104 String& uri = String::Handle(zone);
105 Library& lib = Library::Handle(zone);
106
107 HANDLESCOPE(thread);
108
109 // Ensure there are library objects for all the bootstrap libraries.
110 for (intptr_t i = 0; i < bootstrap_library_count; ++i) {
111 ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index_;
112 uri = Symbols::New(thread, bootstrap_libraries[i].uri_);
113 lib = isolate->object_store()->bootstrap_library(id);
114 ASSERT(lib.raw() == Library::LookupLibrary(thread, uri));
115 if (lib.IsNull()) {
116 lib = Library::NewLibraryHelper(uri, false);
117 lib.SetLoadRequested();
118 lib.Register(thread);
119 isolate->object_store()->set_bootstrap_library(id, lib);
120 }
121 }
122
123 ASSERT(kernel_buffer != NULL);
124 return BootstrapFromKernel(thread, kernel_buffer, kernel_buffer_length);
125 }
126
19 } // namespace dart 127 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698