| OLD | NEW |
| 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" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 Finish(thread, /*from_kernel=*/false); | 310 Finish(thread, /*from_kernel=*/false); |
| 311 } | 311 } |
| 312 // Restore the library tag handler for the isolate. | 312 // Restore the library tag handler for the isolate. |
| 313 isolate->set_library_tag_handler(saved_tag_handler); | 313 isolate->set_library_tag_handler(saved_tag_handler); |
| 314 | 314 |
| 315 return error.raw(); | 315 return error.raw(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 | 318 |
| 319 #if !defined(DART_PRECOMPILED_RUNTIME) | 319 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 320 static RawError* BootstrapFromKernel(Thread* thread, | 320 static RawError* BootstrapFromKernel(Thread* thread, kernel::Program* program) { |
| 321 const uint8_t* buffer, | |
| 322 intptr_t buffer_size) { | |
| 323 Zone* zone = thread->zone(); | 321 Zone* zone = thread->zone(); |
| 324 kernel::KernelReader reader(buffer, buffer_size); | 322 kernel::KernelReader reader(program); |
| 325 kernel::Program* program = reader.ReadPrecompiledProgram(); | |
| 326 if (program == NULL) { | |
| 327 const String& message = | |
| 328 String::Handle(zone, String::New("Failed to read Kernel file")); | |
| 329 return ApiError::New(message); | |
| 330 } | |
| 331 | 323 |
| 332 Isolate* isolate = thread->isolate(); | 324 Isolate* isolate = thread->isolate(); |
| 333 // Mark the already-pending classes. This mark bit will be used to avoid | 325 // Mark the already-pending classes. This mark bit will be used to avoid |
| 334 // adding classes to the list more than once. | 326 // adding classes to the list more than once. |
| 335 GrowableObjectArray& pending_classes = GrowableObjectArray::Handle( | 327 GrowableObjectArray& pending_classes = GrowableObjectArray::Handle( |
| 336 zone, isolate->object_store()->pending_classes()); | 328 zone, isolate->object_store()->pending_classes()); |
| 337 dart::Class& pending = dart::Class::Handle(zone); | 329 dart::Class& pending = dart::Class::Handle(zone); |
| 338 for (intptr_t i = 0; i < pending_classes.Length(); ++i) { | 330 for (intptr_t i = 0; i < pending_classes.Length(); ++i) { |
| 339 pending ^= pending_classes.At(i); | 331 pending ^= pending_classes.At(i); |
| 340 pending.set_is_marked_for_parsing(); | 332 pending.set_is_marked_for_parsing(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 356 library.SetLoaded(); | 348 library.SetLoaded(); |
| 357 break; | 349 break; |
| 358 } | 350 } |
| 359 } | 351 } |
| 360 } | 352 } |
| 361 | 353 |
| 362 Finish(thread, /*from_kernel=*/true); | 354 Finish(thread, /*from_kernel=*/true); |
| 363 return Error::null(); | 355 return Error::null(); |
| 364 } | 356 } |
| 365 #else | 357 #else |
| 366 static RawError* BootstrapFromKernel(Thread* thread, | 358 static RawError* BootstrapFromKernel(Thread* thread, kernel::Program* program) { |
| 367 const uint8_t* buffer, | |
| 368 intptr_t buffer_size) { | |
| 369 UNREACHABLE(); | 359 UNREACHABLE(); |
| 370 return Error::null(); | 360 return Error::null(); |
| 371 } | 361 } |
| 372 #endif | 362 #endif |
| 373 | 363 |
| 374 | 364 |
| 375 RawError* Bootstrap::DoBootstrapping(const uint8_t* kernel_buffer, | 365 RawError* Bootstrap::DoBootstrapping(kernel::Program* kernel_program) { |
| 376 intptr_t kernel_buffer_length) { | |
| 377 Thread* thread = Thread::Current(); | 366 Thread* thread = Thread::Current(); |
| 378 Isolate* isolate = thread->isolate(); | 367 Isolate* isolate = thread->isolate(); |
| 379 Zone* zone = thread->zone(); | 368 Zone* zone = thread->zone(); |
| 380 String& uri = String::Handle(zone); | 369 String& uri = String::Handle(zone); |
| 381 Library& lib = Library::Handle(zone); | 370 Library& lib = Library::Handle(zone); |
| 382 | 371 |
| 383 HANDLESCOPE(thread); | 372 HANDLESCOPE(thread); |
| 384 | 373 |
| 385 // Ensure there are library objects for all the bootstrap libraries. | 374 // Ensure there are library objects for all the bootstrap libraries. |
| 386 for (intptr_t i = 0; i < kBootstrapLibraryCount; ++i) { | 375 for (intptr_t i = 0; i < kBootstrapLibraryCount; ++i) { |
| 387 ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index; | 376 ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index; |
| 388 uri = Symbols::New(thread, bootstrap_libraries[i].uri); | 377 uri = Symbols::New(thread, bootstrap_libraries[i].uri); |
| 389 lib = isolate->object_store()->bootstrap_library(id); | 378 lib = isolate->object_store()->bootstrap_library(id); |
| 390 ASSERT(lib.raw() == Library::LookupLibrary(thread, uri)); | 379 ASSERT(lib.raw() == Library::LookupLibrary(thread, uri)); |
| 391 if (lib.IsNull()) { | 380 if (lib.IsNull()) { |
| 392 lib = Library::NewLibraryHelper(uri, false); | 381 lib = Library::NewLibraryHelper(uri, false); |
| 393 lib.SetLoadRequested(); | 382 lib.SetLoadRequested(); |
| 394 lib.Register(thread); | 383 lib.Register(thread); |
| 395 isolate->object_store()->set_bootstrap_library(id, lib); | 384 isolate->object_store()->set_bootstrap_library(id, lib); |
| 396 } | 385 } |
| 397 } | 386 } |
| 398 | 387 |
| 399 return (kernel_buffer == NULL) | 388 return (kernel_program == NULL) ? BootstrapFromSource(thread) |
| 400 ? BootstrapFromSource(thread) | 389 : BootstrapFromKernel(thread, kernel_program); |
| 401 : BootstrapFromKernel(thread, kernel_buffer, kernel_buffer_length); | |
| 402 } | 390 } |
| 403 | 391 |
| 404 } // namespace dart | 392 } // namespace dart |
| OLD | NEW |