Add DelegateLastClassLoader to the list of WellKnownClassLoaders

Generalize CreatePathClassLoader from the class linker to be able to
create a well known class loader with a given parent.

For now, it only supports PathClassLoader and DelegateLastClassLoader.

Test: m test-art-host
Bug: 38138251
Change-Id: Iced0de7c21010c6d61dbf29a631e670011833a7d
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 684a261..6f06917 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -1533,4 +1533,15 @@
   ASSERT_TRUE(method1_type.Get() != method2_type.Get());
 }
 
+// Verify that ClassLinker's CreateWellknownClassLoader works as expected
+// by creating a chain of class loaders with various dex files.
+TEST_F(ClassLinkerTest, CreateWellKnownClassLoader) {
+  // LoadDexIn*ClassLoader methods already assert that the parent loader is the expected one.
+  // No need to check again.
+  jobject class_loader_a = LoadDexInPathClassLoader("MyClass", nullptr);
+  jobject class_loader_b = LoadDexInDelegateLastClassLoader("Nested", class_loader_a);
+  jobject class_loader_c = LoadDexInPathClassLoader("MultiDex", class_loader_b);
+  LoadDexInDelegateLastClassLoader("Interfaces", class_loader_c);
+}
+
 }  // namespace art