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

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

Powered by Google App Engine
This is Rietveld 408576698