From 97de32773e20297125d4e35e5d7dcb3b6732e063 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 29 Nov 2022 10:30:42 +0000 Subject: Change well known method `String.charAt()` to `ArtMethod*`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Idb34c5de408b98db746d385ae6e012a8997fcc96 --- runtime/native/java_lang_VMClassLoader.cc | 59 ++++++++++++------------------- 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'runtime/native/java_lang_VMClassLoader.cc') diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc index ee40eb1005..b327e51849 100644 --- a/runtime/native/java_lang_VMClassLoader.cc +++ b/runtime/native/java_lang_VMClassLoader.cc @@ -18,7 +18,8 @@ #include "base/zip_archive.h" #include "class_linker.h" -#include "class_root-inl.h" +#include "base/transform_iterator.h" +#include "base/stl_util.h" #include "dex/descriptors_names.h" #include "dex/dex_file_loader.h" #include "dex/utf.h" @@ -33,6 +34,7 @@ #include "nativehelper/scoped_utf_chars.h" #include "obj_ptr.h" #include "scoped_fast_native_object_access-inl.h" +#include "string_array_utils.h" #include "well_known_classes.h" namespace art { @@ -137,46 +139,31 @@ static jobjectArray VMClassLoader_getBootClassPathEntries(JNIEnv* env, jclass) { return !DexFileLoader::IsMultiDexLocation(dex_file->GetLocation().c_str()); }; size_t jar_count = std::count_if(path.begin(), path.end(), is_base_dex); - Thread* self = down_cast(env)->GetSelf(); - ScopedObjectAccess soa(self); - StackHandleScope<1u> hs(self); - Handle> array = hs.NewHandle( - mirror::ObjectArray::Alloc( - self, GetClassRoot>(class_linker), jar_count)); - if (array == nullptr) { - DCHECK(self->IsExceptionPending()); - return nullptr; - } - size_t pos = 0; - for (size_t i = 0, size = path.size(); i != size; ++i) { - const DexFile* dex_file = path[i]; + const DexFile* last_dex_file = nullptr; + auto dchecked_is_base_dex = [&](const DexFile* dex_file) { // For multidex locations, e.g., x.jar!classes2.dex, we want to look into x.jar. // But we do not need to look into the base dex file more than once so we filter // out multidex locations using the fact that they follow the base location. - if (!is_base_dex(dex_file)) { - DCHECK_NE(i, 0u); - DCHECK_EQ(DexFileLoader::GetBaseLocation(dex_file->GetLocation().c_str()), - DexFileLoader::GetBaseLocation(path[i - 1u]->GetLocation().c_str())); - continue; - } - - DCHECK_EQ(DexFileLoader::GetBaseLocation(dex_file->GetLocation().c_str()), - dex_file->GetLocation()); - ObjPtr java_path = - mirror::String::AllocFromModifiedUtf8(self, dex_file->GetLocation().c_str()); - if (java_path == nullptr) { - DCHECK(self->IsExceptionPending()); - return nullptr; + if (kIsDebugBuild) { + if (is_base_dex(dex_file)) { + CHECK_EQ(DexFileLoader::GetBaseLocation(dex_file->GetLocation().c_str()), + dex_file->GetLocation()); + } else { + CHECK(last_dex_file != nullptr); + CHECK_EQ(DexFileLoader::GetBaseLocation(dex_file->GetLocation().c_str()), + DexFileLoader::GetBaseLocation(last_dex_file->GetLocation().c_str())); + } + last_dex_file = dex_file; } - // We're initializing a newly allocated array object, so we do not need to record that under - // a transaction. If the transaction is aborted, the whole object shall be unreachable. - array->SetWithoutChecks( - pos, java_path); - ++pos; - } - DCHECK_EQ(pos, jar_count); - return soa.AddLocalReference(array.Get()); + return is_base_dex(dex_file); + }; + auto get_location = [](const DexFile* dex_file) { return dex_file->GetLocation(); }; + ScopedObjectAccess soa(down_cast(env)->GetSelf()); + return soa.AddLocalReference(CreateStringArray( + soa.Self(), + jar_count, + MakeTransformRange(Filter(path, dchecked_is_base_dex), get_location))); } static JNINativeMethod gMethods[] = { -- cgit v1.2.3-59-g8ed1b