// Whether to allocate full dex cache arrays during startup. Currently disabled // while debugging b/283632504. static constexpr bool kEnableFullArraysAtStartup = false;
void DexCache::VisitReflectiveTargets(ReflectiveValueVisitor* visitor) { bool wrote = false; 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(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 = NativeDexCachePair<ArtField>(
nullptr, NativeDexCachePair<ArtField>::InvalidIndexForSlot(i));
} else {
pair.object = new_val;
}
fields->SetNativePair(i, pair);
wrote = true;
}
} 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(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 = NativeDexCachePair<ArtMethod>(
nullptr, NativeDexCachePair<ArtMethod>::InvalidIndexForSlot(i));
} else {
pair.object = new_val;
}
methods->SetNativePair(i, pair);
wrote = true;
}
}
auto* fields_array = GetResolvedFieldsArray();
num_fields = NumResolvedFieldsArray(); for (size_t i = 0; fields_array != nullptr && i < num_fields; i++) {
ArtField* old_val = fields_array->Get(i); if (old_val == nullptr) { continue;
}
ArtField* new_val = visitor->VisitField(
old_val, DexCacheSourceInfo(kSourceDexCacheResolvedField, i, this)); if (new_val != old_val) {
fields_array->Set(i, new_val);
wrote = true;
}
}
auto* methods_array = GetResolvedMethodsArray();
num_methods = NumResolvedMethodsArray(); for (size_t i = 0; methods_array != nullptr && i < num_methods; i++) {
ArtMethod* old_val = methods_array->Get(i); if (old_val == nullptr) { continue;
}
ArtMethod* new_val = visitor->VisitMethod(
old_val, DexCacheSourceInfo(kSourceDexCacheResolvedMethod, i, this)); if (new_val != old_val) {
methods_array->Set(i, new_val);
wrote = true;
}
}
if (wrote) {
WriteBarrier::ForEveryFieldWrite(this);
}
}
bool DexCache::ShouldAllocateFullArrayAtStartup() { if (!kEnableFullArraysAtStartup) { returnfalse;
}
Runtime* runtime = Runtime::Current(); if (runtime->IsAotCompiler()) { // To save on memory in dex2oat, we don't allocate full arrays by default. returnfalse;
}
if (runtime->IsZygote()) { // Zygote doesn't have a notion of startup. returnfalse;
}
if (runtime->GetStartupCompleted()) { // We only allocate full arrays during app startup. returnfalse;
}
if (GetClassLoader() == nullptr) { // Only allocate full array for app dex files (also note that for // multi-image, the `GetCompilerFilter` call below does not work for // non-primary oat files). returnfalse;
}
const OatDexFile* oat_dex_file = GetDexFile()->GetOatDexFile(); if (oat_dex_file != nullptr &&
CompilerFilter::IsAotCompilationEnabled(oat_dex_file->GetOatFile()->GetCompilerFilter())) { // We only allocate full arrays for dex files where we do not have // compilation. returnfalse;
}
void DexCache::SetResolvedType(dex::TypeIndex type_idx, ObjPtr<Class> resolved) {
DCHECK(resolved != nullptr);
DCHECK(resolved->IsResolved()) << resolved->GetStatus(); // TODO default transaction support. // Use a release store for SetResolvedType. This is done to prevent other threads from seeing a // class but not necessarily seeing the loaded members like the static fields array. // See b/32075261.
SetResolvedTypesEntry(type_idx.index_, resolved.Ptr()); // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
WriteBarrier::ForEveryFieldWrite(this);
if (this == resolved->GetDexCache()) { // If we're updating the dex cache of the class, optimistically update the cache for methods and // fields if the caches are full arrays. auto* resolved_methods = GetResolvedMethodsArray(); if (resolved_methods != nullptr) {
PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize(); // Because there could be duplicate method entries, we make sure we only // update the cache with the first one found to be consistent with method // resolution.
uint32_t previous_method_index = dex::kDexNoIndex; for (ArtMethod& current_method : resolved->GetDeclaredMethods(pointer_size)) {
uint32_t new_index = current_method.GetDexMethodIndex(); if (new_index != previous_method_index) {
resolved_methods->Set(new_index, ¤t_method);
previous_method_index = new_index;
}
}
} auto* resolved_fields = GetResolvedFieldsArray(); if (resolved_fields != nullptr) { for (ArtField& current_field : resolved->GetFields()) {
resolved_fields->Set(current_field.GetDexFieldIndex(), ¤t_field);
}
}
}
}
void DexCache::ClearAllStrings() {
DCHECK(com::android::art::flags::weak_const_string()); auto* array = GetStringsArray(); if (array != nullptr) { for (size_t index : Range(GetDexFile()->NumStringIds())) {
array->Set(index, nullptr);
}
} auto* strings = GetStrings(); if (LIKELY(strings != nullptr)) { for (size_t index : Range(kDexCacheStringCacheSize)) {
strings->Clear(index);
}
}
}
} // namespace mirror
} // namespace art
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.