ART: Refactor String.init binding
Do not use JNI infrastructure, and move the initialization to
the classlinker's FinishInit. This means the binding is available
after the minimal set of initializations.
We could consider moving the functionality even earlier, as soon
as String methods are known and StringFactory can be loaded, but
this placement works well enough and is nicely isolated.
Bug: 79902155
Test: m test-art-host
Change-Id: If4e9f1424668eb200ff5544bc21f5cea6151e4b3
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index be9e08f..b88aa5e 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -828,9 +828,24 @@
return true;
}
+static void CreateStringInitBindings(Thread* self, ClassLinker* class_linker)
+ REQUIRES_SHARED(Locks::mutator_lock_) {
+ // Find String.<init> -> StringFactory bindings.
+ ObjPtr<mirror::Class> string_factory_class =
+ class_linker->FindSystemClass(self, "Ljava/lang/StringFactory;");
+ CHECK(string_factory_class != nullptr);
+ ObjPtr<mirror::Class> string_class =
+ class_linker->GetClassRoot(ClassLinker::ClassRoot::kJavaLangString);
+ WellKnownClasses::InitStringInit(string_class, string_factory_class);
+ // Update the primordial thread.
+ self->InitStringEntryPoints();
+}
+
void ClassLinker::FinishInit(Thread* self) {
VLOG(startup) << "ClassLinker::FinishInit entering";
+ CreateStringInitBindings(self, this);
+
// Let the heap know some key offsets into java.lang.ref instances
// Note: we hard code the field indexes here rather than using FindInstanceField
// as the types of the field can't be resolved prior to the runtime being