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