class ProfileTestHelper { public:
ProfileTestHelper() = default;
using Hotness = ProfileCompilationInfo::MethodHotness; using ProfileInlineCache = ProfileMethodInfo::ProfileInlineCache; using ProfileSampleAnnotation = ProfileCompilationInfo::ProfileSampleAnnotation; using ProfileIndexType = ProfileCompilationInfo::ProfileIndexType;
// Compare different representations of inline caches for equality. staticbool EqualInlineCaches(const std::vector<ProfileMethodInfo::ProfileInlineCache>& expected, const DexFile* dex_file, const ProfileCompilationInfo::MethodHotness& actual_hotness, const ProfileCompilationInfo& info) {
CHECK(actual_hotness.IsHot());
CHECK(actual_hotness.GetInlineCacheMap() != nullptr); const ProfileCompilationInfo::InlineCacheMap& actual = *actual_hotness.GetInlineCacheMap(); if (expected.size() != actual.size()) { returnfalse;
} // The `expected` data should be sorted by dex pc.
CHECK(std::is_sorted(expected.begin(),
expected.end(),
[](auto&& lhs, auto&& rhs) { return lhs.dex_pc < rhs.dex_pc; })); // The `actual` data is a map sorted by dex pc, so we can just iterate over both. auto expected_it = expected.begin(); for (auto it = actual.begin(), end = actual.end(); it != end; ++it, ++expected_it) {
uint32_t dex_pc = it->first; const ProfileCompilationInfo::DexPcData& dex_pc_data = it->second; if (dex_pc != expected_it->dex_pc) { returnfalse;
} if (dex_pc_data.is_missing_types != expected_it->is_missing_types) { returnfalse;
} elseif (dex_pc_data.is_missing_types) { continue; // The classes do not matter if we're missing some types.
} // The `expected_it->is_megamorphic` is not initialized. Check the number of classes. bool expected_is_megamorphic =
(expected_it->classes.size() >= ProfileCompilationInfo::kIndividualInlineCacheSize); if (dex_pc_data.is_megamorphic != expected_is_megamorphic) { returnfalse;
} elseif (dex_pc_data.is_megamorphic) { continue; // The classes do not matter if the inline cache is megamorphic.
} if (dex_pc_data.classes.size() != expected_it->classes.size()) { returnfalse;
} for (dex::TypeIndex type_index : dex_pc_data.classes) { if (std::none_of(expected_it->classes.begin(),
expected_it->classes.end(),
[&](const TypeReference& type_ref) { if (type_ref.dex_file == dex_file) { return type_index == type_ref.TypeIndex();
} else { constchar* expected_descriptor =
type_ref.dex_file->GetTypeDescriptor(type_ref.TypeIndex()); constchar* descriptor = info.GetTypeDescriptor(dex_file, type_index); return strcmp(expected_descriptor, descriptor) == 0;
}
})) { returnfalse;
}
}
} returntrue;
}
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.