Change offline profile to store type_idx of classes.
Changed from storing class_def_idx to type_idx. Allows dexlayout to move
class defs without affecting the profile.
Test: mm test-art-host
Change-Id: I8a040adf0f5f47a1592e18aeb55edde01cb3e1ed
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 8005cdf..aa0d10b 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -968,11 +968,12 @@
return true;
}
DCHECK(profile_compilation_info_ != nullptr);
- bool result = profile_compilation_info_->ContainsClass(dex_file, class_idx);
+ const DexFile::ClassDef& class_def = dex_file.GetClassDef(class_idx);
+ uint16_t type_idx = class_def.class_idx_;
+ bool result = profile_compilation_info_->ContainsClass(dex_file, type_idx);
if (kDebugProfileGuidedCompilation) {
- LOG(INFO) << "[ProfileGuidedCompilation] "
- << (result ? "Verified" : "Skipped") << " method:"
- << dex_file.GetClassDescriptor(dex_file.GetClassDef(class_idx));
+ LOG(INFO) << "[ProfileGuidedCompilation] " << (result ? "Verified" : "Skipped") << " method:"
+ << dex_file.GetClassDescriptor(class_def);
}
return result;
}
diff --git a/dexlayout/dex_visualize.cc b/dexlayout/dex_visualize.cc
index bc9ca6d..7c55659 100644
--- a/dexlayout/dex_visualize.cc
+++ b/dexlayout/dex_visualize.cc
@@ -350,7 +350,8 @@
const uint32_t class_defs_size = header->GetCollections().ClassDefsSize();
for (uint32_t class_index = 0; class_index < class_defs_size; class_index++) {
dex_ir::ClassDef* class_def = header->GetCollections().GetClassDef(class_index);
- if (profile_info_ != nullptr && !profile_info_->ContainsClass(*dex_file, class_index)) {
+ uint16_t type_idx = class_def->ClassType()->GetIndex();
+ if (profile_info_ != nullptr && !profile_info_->ContainsClass(*dex_file, type_idx)) {
continue;
}
dumper->DumpAddressRange(class_def, class_index);
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 65e46c2..4905514 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -8366,17 +8366,16 @@
}
ObjPtr<mirror::DexCache> klass_dex_cache = klass->GetDexCache();
if (klass_dex_cache == dex_cache) {
- const size_t class_def_idx = klass->GetDexClassDefIndex();
DCHECK(klass->IsResolved());
- CHECK_LT(class_def_idx, num_class_defs);
- class_set.insert(class_def_idx);
+ CHECK_LT(klass->GetDexClassDefIndex(), num_class_defs);
+ class_set.insert(klass->GetDexTypeIndex());
}
}
if (!class_set.empty()) {
auto it = ret.find(resolved_classes);
if (it != ret.end()) {
- // Already have the key, union the class def idxs.
+ // Already have the key, union the class type indexes.
it->AddClasses(class_set.begin(), class_set.end());
} else {
resolved_classes.AddClasses(class_set.begin(), class_set.end());
@@ -8419,13 +8418,8 @@
VLOG(profiler) << "Found opened dex file for " << dex_file->GetLocation() << " with "
<< info.GetClasses().size() << " classes";
DCHECK_EQ(dex_file->GetLocationChecksum(), info.GetLocationChecksum());
- for (uint16_t class_def_idx : info.GetClasses()) {
- if (class_def_idx >= dex_file->NumClassDefs()) {
- LOG(WARNING) << "Class def index " << class_def_idx << " >= " << dex_file->NumClassDefs();
- continue;
- }
- const DexFile::TypeId& type_id = dex_file->GetTypeId(
- dex_file->GetClassDef(class_def_idx).class_idx_);
+ for (uint16_t type_idx : info.GetClasses()) {
+ const DexFile::TypeId& type_id = dex_file->GetTypeId(type_idx);
const char* descriptor = dex_file->GetTypeDescriptor(type_id);
ret.insert(descriptor);
}
diff --git a/runtime/jit/offline_profiling_info.cc b/runtime/jit/offline_profiling_info.cc
index f535151..b9f5981 100644
--- a/runtime/jit/offline_profiling_info.cc
+++ b/runtime/jit/offline_profiling_info.cc
@@ -37,7 +37,7 @@
namespace art {
const uint8_t ProfileCompilationInfo::kProfileMagic[] = { 'p', 'r', 'o', '\0' };
-const uint8_t ProfileCompilationInfo::kProfileVersion[] = { '0', '0', '1', '\0' };
+const uint8_t ProfileCompilationInfo::kProfileVersion[] = { '0', '0', '2', '\0' };
static constexpr uint16_t kMaxDexFileKeyLength = PATH_MAX;
@@ -282,12 +282,12 @@
bool ProfileCompilationInfo::AddClassIndex(const std::string& dex_location,
uint32_t checksum,
- uint16_t class_idx) {
+ uint16_t type_idx) {
DexFileData* const data = GetOrAddDexFileData(dex_location, checksum);
if (data == nullptr) {
return false;
}
- data->class_set.insert(class_idx);
+ data->class_set.insert(type_idx);
return true;
}
@@ -304,8 +304,8 @@
}
for (uint16_t i = 0; i < class_set_size; i++) {
- uint16_t class_def_idx = line_buffer.ReadUintAndAdvance<uint16_t>();
- if (!AddClassIndex(dex_location, checksum, class_def_idx)) {
+ uint16_t type_idx = line_buffer.ReadUintAndAdvance<uint16_t>();
+ if (!AddClassIndex(dex_location, checksum, type_idx)) {
return false;
}
}
@@ -569,14 +569,14 @@
return false;
}
-bool ProfileCompilationInfo::ContainsClass(const DexFile& dex_file, uint16_t class_def_idx) const {
+bool ProfileCompilationInfo::ContainsClass(const DexFile& dex_file, uint16_t type_idx) const {
auto info_it = info_.find(GetProfileDexFileKey(dex_file.GetLocation()));
if (info_it != info_.end()) {
if (!ChecksumMatch(dex_file, info_it->second.checksum)) {
return false;
}
const std::set<uint16_t>& classes = info_it->second.class_set;
- return classes.find(class_def_idx) != classes.end();
+ return classes.find(type_idx) != classes.end();
}
return false;
}
@@ -637,7 +637,7 @@
os << "\n\tclasses: ";
for (const auto class_it : dex_data.class_set) {
if (dex_file != nullptr) {
- os << "\n\t\t" << dex_file->GetClassDescriptor(dex_file->GetClassDef(class_it));
+ os << "\n\t\t" << dex_file->PrettyType(class_it);
} else {
os << class_it << ",";
}
@@ -702,11 +702,11 @@
}
for (uint16_t c = 0; c < number_of_classes; c++) {
- uint16_t class_idx = rand() % max_classes;
+ uint16_t type_idx = rand() % max_classes;
if (c < (number_of_classes / kFavorSplit)) {
- class_idx %= kFavorFirstN;
+ type_idx %= kFavorFirstN;
}
- info.AddClassIndex(profile_key, 0, class_idx);
+ info.AddClassIndex(profile_key, 0, type_idx);
}
}
return info.Save(fd);
diff --git a/runtime/jit/offline_profiling_info.h b/runtime/jit/offline_profiling_info.h
index fdca078..f8ed573 100644
--- a/runtime/jit/offline_profiling_info.h
+++ b/runtime/jit/offline_profiling_info.h
@@ -65,8 +65,8 @@
// Returns true if the method reference is present in the profiling info.
bool ContainsMethod(const MethodReference& method_ref) const;
- // Returns true if the class is present in the profiling info.
- bool ContainsClass(const DexFile& dex_file, uint16_t class_def_idx) const;
+ // Returns true if the class's type is present in the profiling info.
+ bool ContainsClass(const DexFile& dex_file, uint16_t type_idx) const;
// Dumps all the loaded profile info into a string and returns it.
// If dex_files is not null then the method indices will be resolved to their
@@ -115,7 +115,7 @@
DexFileData* GetOrAddDexFileData(const std::string& dex_location, uint32_t checksum);
bool AddMethodIndex(const std::string& dex_location, uint32_t checksum, uint16_t method_idx);
- bool AddClassIndex(const std::string& dex_location, uint32_t checksum, uint16_t class_idx);
+ bool AddClassIndex(const std::string& dex_location, uint32_t checksum, uint16_t type_idx);
bool AddResolvedClasses(const DexCacheResolvedClasses& classes);
// Parsing functionality.