Move profman/ to ClassAccessor
Bug: 77709234
Bug: 79758018
Test: test-art-host
Change-Id: I97111ef61a6735ef8719c1a6d7c80ad7c553af51
diff --git a/profman/boot_image_profile.cc b/profman/boot_image_profile.cc
index 89c9eb8..6715680 100644
--- a/profman/boot_image_profile.cc
+++ b/profman/boot_image_profile.cc
@@ -18,6 +18,7 @@
#include <set>
#include "boot_image_profile.h"
+#include "dex/class_accessor-inl.h"
#include "dex/dex_file-inl.h"
#include "dex/method_reference.h"
#include "dex/type_reference.h"
@@ -74,38 +75,31 @@
}
}
// Walk all of the classes and add them to the profile if they meet the requirements.
- for (size_t i = 0; i < dex_file->NumClassDefs(); ++i) {
- const DexFile::ClassDef& class_def = dex_file->GetClassDef(i);
- TypeReference ref(dex_file.get(), class_def.class_idx_);
+ for (ClassAccessor accessor : dex_file->GetClasses()) {
+ TypeReference ref(dex_file.get(), accessor.GetClassIdx());
bool is_clean = true;
- const uint8_t* class_data = dex_file->GetClassData(class_def);
- if (class_data != nullptr) {
- ClassDataItemIterator it(*dex_file, class_data);
- while (it.HasNextStaticField()) {
- const uint32_t flags = it.GetFieldAccessFlags();
- if ((flags & kAccFinal) == 0) {
- // Not final static field will probably dirty the class.
- is_clean = false;
- break;
- }
- it.Next();
+ auto method_visitor = [&](const ClassAccessor::Method& method) {
+ const uint32_t flags = method.GetAccessFlags();
+ if ((flags & kAccNative) != 0) {
+ // Native method will get dirtied.
+ is_clean = false;
}
- it.SkipInstanceFields();
- while (it.HasNextMethod()) {
- const uint32_t flags = it.GetMethodAccessFlags();
- if ((flags & kAccNative) != 0) {
- // Native method will get dirtied.
- is_clean = false;
- break;
- }
- if ((flags & kAccConstructor) != 0 && (flags & kAccStatic) != 0) {
- // Class initializer, may get dirtied (not sure).
- is_clean = false;
- break;
- }
- it.Next();
+ if ((flags & kAccConstructor) != 0 && (flags & kAccStatic) != 0) {
+ // Class initializer, may get dirtied (not sure).
+ is_clean = false;
}
- }
+ };
+ accessor.VisitFieldsAndMethods(
+ [&](const ClassAccessor::Field& field) {
+ if (!field.IsFinal()) {
+ // Not final static field will probably dirty the class.
+ is_clean = false;
+ }
+ },
+ /*instance_fields*/ VoidFunctor(),
+ method_visitor,
+ method_visitor);
+
++(is_clean ? clean_count : dirty_count);
// This counter is how many profiles contain the class.
size_t counter = 0;
diff --git a/profman/profman.cc b/profman/profman.cc
index 1f77239..661132d 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -43,6 +43,7 @@
#include "boot_image_profile.h"
#include "dex/art_dex_file_loader.h"
#include "dex/bytecode_utils.h"
+#include "dex/class_accessor-inl.h"
#include "dex/code_item_accessors-inl.h"
#include "dex/dex_file.h"
#include "dex/dex_file_loader.h"
@@ -929,21 +930,13 @@
dex_resolved_classes.first->AddClass(class_ref.TypeIndex());
std::vector<ProfileMethodInfo> methods;
if (method_str == kClassAllMethods) {
- // Add all of the methods.
- const DexFile::ClassDef* class_def = dex_file->FindClassDef(class_ref.TypeIndex());
- const uint8_t* class_data = dex_file->GetClassData(*class_def);
- if (class_data != nullptr) {
- ClassDataItemIterator it(*dex_file, class_data);
- it.SkipAllFields();
- while (it.HasNextMethod()) {
- if (it.GetMethodCodeItemOffset() != 0) {
- // Add all of the methods that have code to the profile.
- const uint32_t method_idx = it.GetMemberIndex();
- methods.push_back(ProfileMethodInfo(MethodReference(dex_file, method_idx)));
- }
- it.Next();
+ ClassAccessor accessor(*dex_file, *dex_file->FindClassDef(class_ref.TypeIndex()));
+ accessor.VisitMethods([&](const ClassAccessor::Method& method) {
+ if (method.GetCodeItemOffset() != 0) {
+ // Add all of the methods that have code to the profile.
+ methods.push_back(ProfileMethodInfo(method.GetReference()));
}
- }
+ });
}
// TODO: Check return values?
profile->AddMethods(methods, static_cast<ProfileCompilationInfo::MethodHotness::Flag>(flags));