summaryrefslogtreecommitdiff
path: root/runtime/native/java_lang_VMClassLoader.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2022-11-29 10:30:42 +0000
committer Vladimir Marko <vmarko@google.com> 2022-11-30 15:38:00 +0000
commit97de32773e20297125d4e35e5d7dcb3b6732e063 (patch)
tree0d1f79ef1a8b7f82f0b3d70311d0b2ed85707244 /runtime/native/java_lang_VMClassLoader.cc
parent0110e952e488bc41429f6f33f36e8884f41a26d8 (diff)
Change well known method `String.charAt()` to `ArtMethod*`.
Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Idb34c5de408b98db746d385ae6e012a8997fcc96
Diffstat (limited to 'runtime/native/java_lang_VMClassLoader.cc')
-rw-r--r--runtime/native/java_lang_VMClassLoader.cc59
1 files changed, 23 insertions, 36 deletions
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<JNIEnvExt*>(env)->GetSelf();
- ScopedObjectAccess soa(self);
- StackHandleScope<1u> hs(self);
- Handle<mirror::ObjectArray<mirror::String>> array = hs.NewHandle(
- mirror::ObjectArray<mirror::String>::Alloc(
- self, GetClassRoot<mirror::ObjectArray<mirror::String>>(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<mirror::String> 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</*kTransactionActive=*/ false, /*kCheckTransaction=*/ false>(
- pos, java_path);
- ++pos;
- }
- DCHECK_EQ(pos, jar_count);
- return soa.AddLocalReference<jobjectArray>(array.Get());
+ return is_base_dex(dex_file);
+ };
+ auto get_location = [](const DexFile* dex_file) { return dex_file->GetLocation(); };
+ ScopedObjectAccess soa(down_cast<JNIEnvExt*>(env)->GetSelf());
+ return soa.AddLocalReference<jobjectArray>(CreateStringArray(
+ soa.Self(),
+ jar_count,
+ MakeTransformRange(Filter(path, dchecked_is_base_dex), get_location)));
}
static JNINativeMethod gMethods[] = {