summaryrefslogtreecommitdiff
path: root/runtime/mirror/dex_cache.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2022-10-10 12:07:46 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2022-10-13 11:36:34 +0000
commit5111cb6b246c62a40806940076f9e10761f5f41c (patch)
treeef27b3465eef3c219e75d13276cecaf9441d6c4e /runtime/mirror/dex_cache.cc
parentd828fc10982300728d02c97dfac1a0e3684551c8 (diff)
Refactor and cleanup DexCache.
- Introduce macros to avoid duplicating code for each dex cache kind. - Remove preResolvedStrings, this was unused. - Remove dex cache length fields, we can easily infer them. Test: test.py Change-Id: I1e0bc8cf078ce8e09c4d756c63be32cb344fcce1
Diffstat (limited to 'runtime/mirror/dex_cache.cc')
-rw-r--r--runtime/mirror/dex_cache.cc28
1 files changed, 12 insertions, 16 deletions
diff --git a/runtime/mirror/dex_cache.cc b/runtime/mirror/dex_cache.cc
index b7f8ee7a07..1d9fecdd11 100644
--- a/runtime/mirror/dex_cache.cc
+++ b/runtime/mirror/dex_cache.cc
@@ -52,45 +52,47 @@ void DexCache::Initialize(const DexFile* dex_file, ObjPtr<ClassLoader> class_loa
void DexCache::VisitReflectiveTargets(ReflectiveValueVisitor* visitor) {
bool wrote = false;
- FieldDexCacheType* fields = GetResolvedFields();
+ auto* fields = GetResolvedFields();
size_t num_fields = NumResolvedFields();
// Check both the data pointer and count since the array might be initialized
// concurrently on other thread, and we might observe just one of the values.
for (size_t i = 0; fields != nullptr && i < num_fields; i++) {
- auto pair(GetNativePair(fields, i));
- if (pair.index == FieldDexCachePair::InvalidIndexForSlot(i)) {
+ auto pair(fields->GetNativePair(i));
+ if (pair.index == NativeDexCachePair<ArtField>::InvalidIndexForSlot(i)) {
continue;
}
ArtField* new_val = visitor->VisitField(
pair.object, DexCacheSourceInfo(kSourceDexCacheResolvedField, pair.index, this));
if (UNLIKELY(new_val != pair.object)) {
if (new_val == nullptr) {
- pair = FieldDexCachePair(nullptr, FieldDexCachePair::InvalidIndexForSlot(i));
+ pair = NativeDexCachePair<ArtField>(
+ nullptr, NativeDexCachePair<ArtField>::InvalidIndexForSlot(i));
} else {
pair.object = new_val;
}
- SetNativePair(fields, i, pair);
+ fields->SetNativePair(i, pair);
wrote = true;
}
}
- MethodDexCacheType* methods = GetResolvedMethods();
+ auto* methods = GetResolvedMethods();
size_t num_methods = NumResolvedMethods();
// Check both the data pointer and count since the array might be initialized
// concurrently on other thread, and we might observe just one of the values.
for (size_t i = 0; methods != nullptr && i < num_methods; i++) {
- auto pair(GetNativePair(methods, i));
- if (pair.index == MethodDexCachePair::InvalidIndexForSlot(i)) {
+ auto pair(methods->GetNativePair(i));
+ if (pair.index == NativeDexCachePair<ArtMethod>::InvalidIndexForSlot(i)) {
continue;
}
ArtMethod* new_val = visitor->VisitMethod(
pair.object, DexCacheSourceInfo(kSourceDexCacheResolvedMethod, pair.index, this));
if (UNLIKELY(new_val != pair.object)) {
if (new_val == nullptr) {
- pair = MethodDexCachePair(nullptr, MethodDexCachePair::InvalidIndexForSlot(i));
+ pair = NativeDexCachePair<ArtMethod>(
+ nullptr, NativeDexCachePair<ArtMethod>::InvalidIndexForSlot(i));
} else {
pair.object = new_val;
}
- SetNativePair(methods, i, pair);
+ methods->SetNativePair(i, pair);
wrote = true;
}
}
@@ -106,12 +108,6 @@ void DexCache::ResetNativeArrays() {
SetResolvedFields(nullptr);
SetResolvedMethodTypes(nullptr);
SetResolvedCallSites(nullptr);
- SetField32<false>(NumStringsOffset(), 0);
- SetField32<false>(NumResolvedTypesOffset(), 0);
- SetField32<false>(NumResolvedMethodsOffset(), 0);
- SetField32<false>(NumResolvedFieldsOffset(), 0);
- SetField32<false>(NumResolvedMethodTypesOffset(), 0);
- SetField32<false>(NumResolvedCallSitesOffset(), 0);
}
void DexCache::SetLocation(ObjPtr<mirror::String> location) {