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

Unified Diff: runtime/vm/kernel_reader.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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/kernel_reader.cc
diff --git a/runtime/vm/kernel_reader.cc b/runtime/vm/kernel_reader.cc
index f9f22777b7ae86993842f9d91b210ed5645c5efc..6c669e4d745470a16444b0acf6f0211d5e6f2fc5 100644
--- a/runtime/vm/kernel_reader.cc
+++ b/runtime/vm/kernel_reader.cc
@@ -12,6 +12,7 @@
#include "vm/parser.h"
#include "vm/symbols.h"
+#if !defined(DART_PRECOMPILED_RUNTIME)
namespace dart {
namespace kernel {
@@ -81,19 +82,18 @@ class SimpleExpressionConverter : public ExpressionVisitor {
dart::Instance* simple_value_;
};
-void BuildingTranslationHelper::SetFinalize(bool finalize) {
- reader_->finalize_ = finalize;
-}
RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary(
Library* library) {
return reader_->LookupLibrary(library).raw();
}
+
RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) {
return reader_->LookupClass(klass).raw();
}
+
Object& KernelReader::ReadProgram() {
ASSERT(!bootstrapping_);
Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_);
@@ -113,29 +113,13 @@ Object& KernelReader::ReadProgram() {
ReadLibrary(kernel_library);
}
- // We finalize classes after we've constructed all classes since we
- // currently don't construct them in pre-order of the class hierarchy (and
- // finalization of a class needs all of its superclasses to be finalized).
- dart::String& name = dart::String::Handle(Z);
for (intptr_t i = 0; i < length; i++) {
- Library* kernel_library = program->libraries()[i];
- dart::Library& library = LookupLibrary(kernel_library);
- name = library.url();
-
- // TODO(27590) unskip this library when we fix underlying issue.
- if (name.Equals("dart:vmservice_io")) {
- continue;
- }
+ dart::Library& library = LookupLibrary(program->libraries()[i]);
+ if (!library.Loaded()) library.SetLoaded();
+ }
- if (!library.Loaded()) {
- dart::Class& klass = dart::Class::Handle(Z);
- for (intptr_t i = 0; i < kernel_library->classes().length(); i++) {
- klass = LookupClass(kernel_library->classes()[i]).raw();
- ClassFinalizer::FinalizeTypesInClass(klass);
- ClassFinalizer::FinalizeClass(klass);
- }
- library.SetLoaded();
- }
+ if (!ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) {
+ FATAL("Error in class finalization during bootstrapping.");
}
dart::Library& library = LookupLibrary(kernel_main_library);
@@ -161,6 +145,7 @@ Object& KernelReader::ReadProgram() {
}
}
+
void KernelReader::ReadLibrary(Library* kernel_library) {
dart::Library& library = LookupLibrary(kernel_library);
if (library.Loaded()) return;
@@ -217,13 +202,17 @@ void KernelReader::ReadLibrary(Library* kernel_library) {
ReadProcedure(library, toplevel_class, kernel_procedure);
}
+ const GrowableObjectArray& classes =
+ GrowableObjectArray::Handle(I->object_store()->pending_classes());
+
// Load all classes.
for (intptr_t i = 0; i < kernel_library->classes().length(); i++) {
Class* kernel_klass = kernel_library->classes()[i];
- ReadClass(library, kernel_klass);
+ classes.Add(ReadClass(library, kernel_klass), Heap::kOld);
}
}
+
void KernelReader::ReadPreliminaryClass(dart::Class* klass,
Class* kernel_klass) {
ASSERT(kernel_klass->IsNormalClass());
@@ -284,7 +273,6 @@ void KernelReader::ReadPreliminaryClass(dart::Class* klass,
intptr_t interface_count = kernel_klass->implemented_classes().length();
const dart::Array& interfaces =
dart::Array::Handle(Z, dart::Array::New(interface_count));
- dart::Class& interface_class = dart::Class::Handle(Z);
for (intptr_t i = 0; i < interface_count; i++) {
InterfaceType* kernel_interface_type =
kernel_klass->implemented_classes()[i];
@@ -292,33 +280,14 @@ void KernelReader::ReadPreliminaryClass(dart::Class* klass,
T.TranslateTypeWithoutFinalization(kernel_interface_type);
if (type.IsMalformed()) H.ReportError("Malformed interface type.");
interfaces.SetAt(i, type);
-
- // NOTE: Normally the DartVM keeps a list of pending classes and iterates
- // through them later on using `ClassFinalizer::ProcessPendingClasses()`.
- // This involes calling `ClassFinalizer::ResolveSuperTypeAndInterfaces()`
- // which does a lot of error validation (e.g. cycle checks) which we don't
- // need here. But we do need to do one thing which this resolving phase
- // normally does for us: set the `is_implemented` boolean.
-
- // TODO(27590): Maybe we can do this differently once we have
- // "bootstrapping from kernel"-support.
- interface_class = type.type_class();
- interface_class.set_is_implemented();
}
klass->set_interfaces(interfaces);
if (kernel_klass->is_abstract()) klass->set_is_abstract();
- klass->set_is_cycle_free();
-
- // When bootstrapping we should not finalize types yet because they will be
- // finalized when the object store's pending_classes list is drained by
- // ClassFinalizer::ProcessPendingClasses. Even when not bootstrapping we are
- // careful not to eagerly finalize types that may introduce a circularity
- // (such as type arguments, interface types, field types, etc.).
- if (finalize_) ClassFinalizer::FinalizeTypesInClass(*klass);
}
-void KernelReader::ReadClass(const dart::Library& library,
- Class* kernel_klass) {
+
+dart::Class& KernelReader::ReadClass(const dart::Library& library,
+ Class* kernel_klass) {
// This will trigger a call to [ReadPreliminaryClass] if not already done.
dart::Class& klass = LookupClass(kernel_klass);
@@ -383,8 +352,11 @@ void KernelReader::ReadClass(const dart::Library& library,
GrowableObjectArray::Handle(Z, I->object_store()->pending_classes())
.Add(klass, Heap::kOld);
}
+
+ return klass;
}
+
void KernelReader::ReadProcedure(const dart::Library& library,
const dart::Class& owner,
Procedure* kernel_procedure,
@@ -524,6 +496,7 @@ void KernelReader::GenerateFieldAccessors(const dart::Class& klass,
}
}
+
void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper,
DartTypeTranslator type_translator,
const dart::Class& klass,
@@ -594,6 +567,7 @@ void KernelReader::SetupFunctionParameters(TranslationHelper translation_helper,
: return_type);
}
+
void KernelReader::SetupFieldAccessorFunction(const dart::Class& klass,
const dart::Function& function) {
bool is_setter = function.IsImplicitSetterFunction();
@@ -679,6 +653,7 @@ dart::Class& KernelReader::LookupClass(Class* klass) {
return *handle;
}
+
RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) {
intptr_t lookuptable[] = {
RawFunction::kRegularFunction, // Procedure::kMethod
@@ -696,5 +671,7 @@ RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) {
}
}
+
} // namespace kernel
} // namespace dart
+#endif // !defined(DART_PRECOMPILED_RUNTIME)

Powered by Google App Engine
This is Rietveld 408576698