Clean up profile AddClass APIs
Remove AddClassIndex APIs which were only used in tests (or test profile generation).
This was the last API which exposed the profile key internals.
Bug: 139884006
Test: m test-art-host
Change-Id: Iea41b85484c7f1ec33eaad75cd18c65adcb7853e
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index e866330..81366e4 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -52,7 +52,6 @@
namespace art {
-static constexpr size_t kMaxMethodIds = 65535;
static constexpr bool kDebugArgs = false;
static const char* kDisableCompactDex = "--compact-dex-level=none";
@@ -630,21 +629,22 @@
// Ignore, we'll do our own checks.
}
- // Emits a profile with a single dex file with the given location and a single class index of 1.
+ // Emits a profile with a single dex file with the given location and classes ranging
+ // from 0 to num_classes.
void GenerateProfile(const std::string& test_profile,
- const std::string& dex_location,
- size_t num_classes,
- uint32_t checksum) {
+ const DexFile* dex,
+ size_t num_classes) {
int profile_test_fd = open(test_profile.c_str(),
O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
0644);
CHECK_GE(profile_test_fd, 0);
ProfileCompilationInfo info;
- std::string profile_key = info.GetProfileDexFileKey(dex_location);
+ std::vector<dex::TypeIndex> classes;;
for (size_t i = 0; i < num_classes; ++i) {
- info.AddClassIndex(profile_key, checksum, dex::TypeIndex(1 + i), kMaxMethodIds);
+ classes.push_back(dex::TypeIndex(1 + i));
}
+ info.AddClassesForDex(dex, classes.begin(), classes.end());
bool result = info.Save(profile_test_fd);
close(profile_test_fd);
ASSERT_TRUE(result);
@@ -666,10 +666,7 @@
location, location, /*verify=*/ true, /*verify_checksum=*/ true, &error_msg, &dex_files));
EXPECT_EQ(dex_files.size(), 1U);
std::unique_ptr<const DexFile>& dex_file = dex_files[0];
- GenerateProfile(profile_location,
- dex_location,
- num_profile_classes,
- dex_file->GetLocationChecksum());
+ GenerateProfile(profile_location, dex_file.get(), num_profile_classes);
std::vector<std::string> copy(extra_args);
copy.push_back("--profile-file=" + profile_location);
std::unique_ptr<File> app_image_file;
diff --git a/libprofile/profile/profile_compilation_info.cc b/libprofile/profile/profile_compilation_info.cc
index afefa79..1791610 100644
--- a/libprofile/profile/profile_compilation_info.cc
+++ b/libprofile/profile/profile_compilation_info.cc
@@ -679,18 +679,6 @@
return true;
}
-bool ProfileCompilationInfo::AddClassIndex(const std::string& profile_key,
- uint32_t checksum,
- dex::TypeIndex type_idx,
- uint32_t num_method_ids) {
- DexFileData* const data = GetOrAddDexFileData(profile_key, checksum, num_method_ids);
- if (data == nullptr) {
- return false;
- }
- data->class_set.insert(type_idx);
- return true;
-}
-
#define READ_UINT(type, buffer, dest, error) \
do { \
if (!(buffer).ReadUintAndAdvance<type>(&(dest))) { \
@@ -805,12 +793,14 @@
READ_UINT(uint16_t, buffer, diff_with_last_class_index, error);
uint16_t type_index = last_class_index + diff_with_last_class_index;
last_class_index = type_index;
- if (!AddClassIndex(line_header.profile_key,
- line_header.checksum,
- dex::TypeIndex(type_index),
- line_header.num_method_ids)) {
- return false;
+
+ DexFileData* const data = GetOrAddDexFileData(line_header.profile_key,
+ line_header.checksum,
+ line_header.num_method_ids);
+ if (data == nullptr) {
+ return false;
}
+ data->class_set.insert(dex::TypeIndex(type_index));
}
size_t total_bytes_read = unread_bytes_before_op - buffer.CountUnreadBytes();
uint32_t expected_bytes_read = line_header.class_set_size * sizeof(uint16_t);
diff --git a/libprofile/profile/profile_compilation_info.h b/libprofile/profile/profile_compilation_info.h
index 125f6e8..3cd3bfa 100644
--- a/libprofile/profile/profile_compilation_info.h
+++ b/libprofile/profile/profile_compilation_info.h
@@ -583,12 +583,6 @@
dex_file->NumMethodIds());
}
- // Add a class index to the profile.
- bool AddClassIndex(const std::string& profile_key,
- uint32_t checksum,
- dex::TypeIndex type_idx,
- uint32_t num_method_ids);
-
// Encode the known dex_files into a vector. The index of a dex_reference will
// be the same as the profile index of the dex file (used to encode the ClassReferences).
void DexFileToProfileIndex(/*out*/std::vector<DexReference>* dex_references) const;
diff --git a/libprofile/profile/profile_compilation_info_test.cc b/libprofile/profile/profile_compilation_info_test.cc
index 766c10e..a9c4b46 100644
--- a/libprofile/profile/profile_compilation_info_test.cc
+++ b/libprofile/profile/profile_compilation_info_test.cc
@@ -88,12 +88,11 @@
Hotness::kFlagHot);
}
- bool AddClass(const std::string& dex_location,
- uint32_t checksum,
- dex::TypeIndex type_index,
- ProfileCompilationInfo* info) {
- return info->AddClassIndex(
- info->GetProfileDexFileKey(dex_location), checksum, type_index, kMaxMethodIds);
+ bool AddClass(ProfileCompilationInfo* info,
+ const DexFile* dex,
+ dex::TypeIndex type_index) {
+ std::vector<dex::TypeIndex> classes = {type_index};
+ return info->AddClassesForDex(dex, classes.begin(), classes.end());
}
uint32_t GetFd(const ScratchFile& file) {
@@ -377,8 +376,8 @@
}
// Save the maximum number of classes
for (uint16_t i = 0; i < std::numeric_limits<uint16_t>::max(); i++) {
- ASSERT_TRUE(AddClass("dex_location1", /* checksum= */ 1, dex::TypeIndex(i), &saved_info));
- ASSERT_TRUE(AddClass("dex_location2", /* checksum= */ 2, dex::TypeIndex(i), &saved_info));
+ ASSERT_TRUE(AddClass(&saved_info, dex1, dex::TypeIndex(i)));
+ ASSERT_TRUE(AddClass(&saved_info, dex2, dex::TypeIndex(i)));
}
ASSERT_TRUE(saved_info.Save(GetFd(profile)));
@@ -1136,8 +1135,8 @@
ProfileCompilationInfo saved_info;
uint16_t item_count = 1000;
for (uint16_t i = 0; i < item_count; i++) {
- ASSERT_TRUE(AddClass("dex_location1", /* checksum= */ 1, dex::TypeIndex(i), &saved_info));
- ASSERT_TRUE(AddClass("dex_location2", /* checksum= */ 2, dex::TypeIndex(i), &saved_info));
+ ASSERT_TRUE(AddClass(&saved_info, dex1, dex::TypeIndex(i)));
+ ASSERT_TRUE(AddClass(&saved_info, dex2, dex::TypeIndex(i)));
}
ASSERT_TRUE(saved_info.Save(GetFd(profile)));
@@ -1148,15 +1147,15 @@
ProfileCompilationInfo loaded_info;
ASSERT_TRUE(profile.GetFile()->ResetOffset());
ProfileCompilationInfo::ProfileLoadFilterFn filter_fn =
- [](const std::string& dex_location, uint32_t checksum) -> bool {
- return (dex_location == "dex_location2" && checksum == 2);
+ [&dex2 = dex2](const std::string& dex_location, uint32_t checksum) -> bool {
+ return (dex_location == dex2->GetLocation() && checksum == dex2->GetLocationChecksum());
};
ASSERT_TRUE(loaded_info.Load(GetFd(profile), true, filter_fn));
// Compute the expectation.
ProfileCompilationInfo expected_info;
for (uint16_t i = 0; i < item_count; i++) {
- ASSERT_TRUE(AddClass("dex_location2", /* checksum= */ 2, dex::TypeIndex(i), &expected_info));
+ ASSERT_TRUE(AddClass(&expected_info, dex2, dex::TypeIndex(i)));
}
// Validate the expectation.
diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc
index e00cc75..e6ff745 100644
--- a/profman/profile_assistant_test.cc
+++ b/profman/profile_assistant_test.cc
@@ -71,6 +71,13 @@
flags);
}
+ bool AddClass(ProfileCompilationInfo* info,
+ const DexFile* dex,
+ dex::TypeIndex type_index) {
+ std::vector<dex::TypeIndex> classes = {type_index};
+ return info->AddClassesForDex(dex, classes.begin(), classes.end());
+ }
+
void SetupProfile(const DexFile* dex_file1,
const DexFile* dex_file2,
uint16_t number_of_methods,
@@ -94,10 +101,7 @@
}
}
for (uint16_t i = 0; i < number_of_classes; i++) {
- ASSERT_TRUE(info->AddClassIndex(info->GetProfileDexFileKey(dex_file1->GetLocation()),
- dex_file1->GetLocationChecksum(),
- dex::TypeIndex(i),
- dex_file1->NumMethodIds()));
+ ASSERT_TRUE(AddClass(info, dex_file1, dex::TypeIndex(i)));
}
ASSERT_TRUE(info->Save(GetFd(profile)));