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

Side by Side Diff: runtime/vm/bootstrap.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/bootstrap_natives.h" 9 #include "vm/bootstrap_natives.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
11 #include "vm/compiler.h" 11 #include "vm/compiler.h"
12 #include "vm/dart_api_impl.h" 12 #include "vm/dart_api_impl.h"
13 #include "vm/kernel.h"
14 #include "vm/kernel_reader.h"
13 #include "vm/object.h" 15 #include "vm/object.h"
14 #include "vm/object_store.h" 16 #include "vm/object_store.h"
15 #include "vm/symbols.h" 17 #include "vm/symbols.h"
16 18
17 namespace dart { 19 namespace dart {
18 20
19 21
20 struct BootstrapLibProps { 22 struct BootstrapLibProps {
21 ObjectStore::BootstrapLibraryId index; 23 ObjectStore::BootstrapLibraryId index;
22 const char* uri; 24 const char* uri;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 script = Script::New(patch_file_uri, source, RawScript::kPatchTag); 244 script = Script::New(patch_file_uri, source, RawScript::kPatchTag);
243 error = lib.Patch(script); 245 error = lib.Patch(script);
244 if (!error.IsNull()) { 246 if (!error.IsNull()) {
245 return error.raw(); 247 return error.raw();
246 } 248 }
247 } 249 }
248 return Error::null(); 250 return Error::null();
249 } 251 }
250 252
251 253
254 static void Finish(Thread* thread, bool from_kernel) {
255 Bootstrap::SetupNativeResolver();
256 if (!ClassFinalizer::ProcessPendingClasses(from_kernel)) {
257 FATAL("Error in class finalization during bootstrapping.");
258 }
259
260 // Eagerly compile the _Closure class as it is the class of all closure
261 // instances. This allows us to just finalize function types without going
262 // through the hoops of trying to compile their scope class.
263 ObjectStore* object_store = thread->isolate()->object_store();
264 Class& cls = Class::Handle(thread->zone(), object_store->closure_class());
265 Compiler::CompileClass(cls);
266 // Eagerly compile Bool class, bool constants are used from within compiler.
267 cls = object_store->bool_class();
268 Compiler::CompileClass(cls);
269 }
270
271
252 static RawError* BootstrapFromSource(Thread* thread) { 272 static RawError* BootstrapFromSource(Thread* thread) {
253 Isolate* isolate = thread->isolate(); 273 Isolate* isolate = thread->isolate();
254 Zone* zone = thread->zone(); 274 Zone* zone = thread->zone();
255 String& uri = String::Handle(zone); 275 String& uri = String::Handle(zone);
256 String& source = String::Handle(zone); 276 String& source = String::Handle(zone);
257 Script& script = Script::Handle(zone); 277 Script& script = Script::Handle(zone);
258 Library& lib = Library::Handle(zone); 278 Library& lib = Library::Handle(zone);
259 Error& error = Error::Handle(zone); 279 Error& error = Error::Handle(zone);
260 280
261 // Set the library tag handler for the isolate to the bootstrap 281 // Set the library tag handler for the isolate to the bootstrap
(...skipping 21 matching lines...) Expand all
283 break; 303 break;
284 } 304 }
285 // If a patch exists, load and patch the script. 305 // If a patch exists, load and patch the script.
286 error = LoadPatchFiles(thread, lib, i); 306 error = LoadPatchFiles(thread, lib, i);
287 if (!error.IsNull()) { 307 if (!error.IsNull()) {
288 break; 308 break;
289 } 309 }
290 } 310 }
291 311
292 if (error.IsNull()) { 312 if (error.IsNull()) {
293 Bootstrap::SetupNativeResolver(); 313 Finish(thread, /*from_kernel=*/false);
294 ClassFinalizer::ProcessPendingClasses();
295
296 // Eagerly compile the _Closure class as it is the class of all closure
297 // instances. This allows us to just finalize function types
298 // without going through the hoops of trying to compile their scope class.
299 Class& cls = Class::Handle(zone, isolate->object_store()->closure_class());
300 Compiler::CompileClass(cls);
301 // Eagerly compile Bool class, bool constants are used from within compiler.
302 cls = isolate->object_store()->bool_class();
303 Compiler::CompileClass(cls);
304 } 314 }
305
306 // Restore the library tag handler for the isolate. 315 // Restore the library tag handler for the isolate.
307 isolate->set_library_tag_handler(saved_tag_handler); 316 isolate->set_library_tag_handler(saved_tag_handler);
308 317
309 return error.raw(); 318 return error.raw();
310 } 319 }
311 320
312 321
313 RawError* Bootstrap::DoBootstrapping() { 322 static RawError* BootstrapFromKernel(Thread* thread,
323 const uint8_t* buffer,
324 intptr_t buffer_size) {
325 Zone* zone = thread->zone();
326 kernel::Program* program =
327 ReadPrecompiledKernelFromBuffer(buffer, buffer_size);
328 if (program == NULL) {
329 const String& message =
330 String::Handle(zone, String::New("Failed to read Kernel file"));
331 return ApiError::New(message);
332 }
333
334 Isolate* isolate = thread->isolate();
335 // Mark the already-pending classes. This mark bit will be used to avoid
336 // adding classes to the list more than once.
337 GrowableObjectArray& pending_classes = GrowableObjectArray::Handle(
338 zone, isolate->object_store()->pending_classes());
339 dart::Class& pending = dart::Class::Handle(zone);
340 for (intptr_t i = 0; i < pending_classes.Length(); ++i) {
341 pending ^= pending_classes.At(i);
342 pending.set_is_marked_for_parsing();
343 }
344
345 Library& library = Library::Handle(zone);
346 String& dart_name = String::Handle(zone);
347 String& kernel_name = String::Handle(zone);
348 kernel::KernelReader reader(NULL, -1, true);
349 for (intptr_t i = 0; i < kBootstrapLibraryCount; ++i) {
350 ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index;
351 library = isolate->object_store()->bootstrap_library(id);
352 dart_name = library.url();
353 for (intptr_t j = 0; j < program->libraries().length(); ++j) {
354 kernel::Library* kernel_library = program->libraries()[j];
355 kernel::String* uri = kernel_library->import_uri();
356 kernel_name = Symbols::FromUTF8(thread, uri->buffer(), uri->size());
357 if (kernel_name.Equals(dart_name)) {
358 reader.ReadLibrary(kernel_library);
359 library.SetLoaded();
360 break;
361 }
362 }
363 }
364
365 Finish(thread, /*from_kernel=*/true);
366 return Error::null();
367 }
368
369
370 RawError* Bootstrap::DoBootstrapping(const uint8_t* kernel_buffer,
371 intptr_t kernel_buffer_length) {
314 Thread* thread = Thread::Current(); 372 Thread* thread = Thread::Current();
315 Isolate* isolate = thread->isolate(); 373 Isolate* isolate = thread->isolate();
316 Zone* zone = thread->zone(); 374 Zone* zone = thread->zone();
317 String& uri = String::Handle(zone); 375 String& uri = String::Handle(zone);
318 Library& lib = Library::Handle(zone); 376 Library& lib = Library::Handle(zone);
319 377
320 HANDLESCOPE(thread); 378 HANDLESCOPE(thread);
321 379
322 // Ensure there are library objects for all the bootstrap libraries. 380 // Ensure there are library objects for all the bootstrap libraries.
323 for (intptr_t i = 0; i < kBootstrapLibraryCount; ++i) { 381 for (intptr_t i = 0; i < kBootstrapLibraryCount; ++i) {
324 ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index; 382 ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index;
325 uri = Symbols::New(thread, bootstrap_libraries[i].uri); 383 uri = Symbols::New(thread, bootstrap_libraries[i].uri);
326 lib = isolate->object_store()->bootstrap_library(id); 384 lib = isolate->object_store()->bootstrap_library(id);
327 ASSERT(lib.raw() == Library::LookupLibrary(thread, uri)); 385 ASSERT(lib.raw() == Library::LookupLibrary(thread, uri));
328 if (lib.IsNull()) { 386 if (lib.IsNull()) {
329 lib = Library::NewLibraryHelper(uri, false); 387 lib = Library::NewLibraryHelper(uri, false);
330 lib.SetLoadRequested(); 388 lib.SetLoadRequested();
331 lib.Register(thread); 389 lib.Register(thread);
332 isolate->object_store()->set_bootstrap_library(id, lib); 390 isolate->object_store()->set_bootstrap_library(id, lib);
333 } 391 }
334 } 392 }
335 393
336 return BootstrapFromSource(thread); 394 return (kernel_buffer == NULL)
395 ? BootstrapFromSource(thread)
396 : BootstrapFromKernel(thread, kernel_buffer, kernel_buffer_length);
337 } 397 }
338 398
339 } // namespace dart 399 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698