[vm] Move main ObjectStore initialization right after bootstrapping but before loading user classes
This CL fixes AOT failures that happened after [0] landed. That code
removed lookup code for the `future_class()` in the
`ObjectStore::LazyInit*()` methods and replaced it with an assert instead.
The change was correct, since the lazy members should be initialized
on-demand - after the core, non-lazy members.
=> Though this seemed to not be the case in AOT, which hit the assert.
The reason [0] only caused failures in AOT is because in JIT the VM is
bootstrapped only from the vm_platform.dill file and as a secondary
embedder call the application.dill file is loaded.
Yet in AOT we have a combined full_application.dill which will all be
loaded during bootstrapping. That has caused the application to be
loaded before `ObjectStore::InitKnownObjects()` was invoked.
The initialization of [ObjectStore] which contains common core library
classes/functions/fields should happen before we use the kernel loader
to load user classes (since general kernel loading depends on the
[ObjectStore] being populated).
This also ensures that `ObjectStore::InitKnownObjects()` will be called
before `ObjectStore::LazyInit*()` - since they depend on the former having
run (e.g. that the non-lazy `future_class()` member of `ObjectStore`
was set).
[0] https://dart-review.googlesource.com/c/sdk/+/206782
TEST=Fixes AOT builders.
Change-Id: I0861d1a2f39effbcea08d7796742845b874a0084
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207002
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/vm/bootstrap.cc b/runtime/vm/bootstrap.cc
index 5e3ddd7..20d63d2 100644
--- a/runtime/vm/bootstrap.cc
+++ b/runtime/vm/bootstrap.cc
@@ -128,6 +128,8 @@
// Finish bootstrapping, including class finalization.
Finish(thread);
+ isolate_group->object_store()->InitKnownObjects();
+
// The platform binary may contain other libraries (e.g., dart:_builtin or
// dart:io) that will not be bundled with application. Load them now.
const Object& result = Object::Handle(zone, loader.LoadProgram());
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 26c206d..59a2fb6 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -2397,8 +2397,6 @@
const bool injected = cls.InjectCIDFields();
ASSERT(injected);
- isolate_group->object_store()->InitKnownObjects();
-
// Set up recognized state of all functions (core, math and typed data).
MethodRecognizer::InitializeState();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
diff --git a/runtime/vm/object_store.cc b/runtime/vm/object_store.cc
index 8b84d23..b3decbb 100644
--- a/runtime/vm/object_store.cc
+++ b/runtime/vm/object_store.cc
@@ -282,11 +282,13 @@
cls = core_lib.LookupClassAllowPrivate(Symbols::Pragma());
ASSERT(!cls.IsNull());
set_pragma_class(cls);
+ RELEASE_ASSERT(cls.EnsureIsFinalized(thread) == Error::null());
set_pragma_name(Field::Handle(zone, cls.LookupField(Symbols::name())));
set_pragma_options(Field::Handle(zone, cls.LookupField(Symbols::options())));
cls = core_lib.LookupClassAllowPrivate(Symbols::_GrowableList());
ASSERT(!cls.IsNull());
+ RELEASE_ASSERT(cls.EnsureIsFinalized(thread) == Error::null());
growable_list_factory_ =
cls.LookupFactoryAllowPrivate(Symbols::_GrowableListFactory());
ASSERT(growable_list_factory_ != Function::null());
@@ -306,6 +308,7 @@
// Ensure AddSmiSmiCheckForFastSmiStubs run by the background compiler
// will not create new functions.
const Class& smi_class = Class::Handle(zone, this->smi_class());
+ RELEASE_ASSERT(smi_class.EnsureIsFinalized(thread) == Error::null());
function_name =
Function::CreateDynamicInvocationForwarderName(Symbols::Plus());
Resolver::ResolveDynamicAnyArgs(zone, smi_class, function_name);