[compiler] Predictable compilation dependency installation

--predictable requires deterministic heap allocation sequences.
Guarantee these for compilation dependency installation by sorting the
dependency list if --predictable is enabled.

Bug: v8:12397
Change-Id: Ia4660f2249a1c3390a932ae057a5b4d4537497ab
Fixed: v8:12447
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3306488
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78158}
This commit is contained in:
Jakob Gruber 2021-11-30 13:22:51 +01:00 committed by V8 LUCI CQ
parent f4e02f266b
commit 1976cbfb36

View File

@ -119,6 +119,11 @@ class PendingDependencies final {
}
void InstallAll(Isolate* isolate, Handle<Code> code) {
if (V8_UNLIKELY(FLAG_predictable)) {
InstallAllPredictable(isolate, code);
return;
}
// With deduplication done we no longer rely on the object address for
// hashing.
AllowGarbageCollection yes_gc;
@ -128,6 +133,27 @@ class PendingDependencies final {
}
}
void InstallAllPredictable(Isolate* isolate, Handle<Code> code) {
CHECK(FLAG_predictable);
// First, guarantee predictable iteration order.
using HandleAndGroup =
std::pair<Handle<HeapObject>, DependentCode::DependencyGroups>;
std::vector<HandleAndGroup> entries(deps_.begin(), deps_.end());
std::sort(entries.begin(), entries.end(),
[](const HandleAndGroup& lhs, const HandleAndGroup& rhs) {
return lhs.first->ptr() < rhs.first->ptr();
});
// With deduplication done we no longer rely on the object address for
// hashing.
AllowGarbageCollection yes_gc;
for (const auto& o_and_g : entries) {
DependentCode::InstallDependency(isolate, code, o_and_g.first,
o_and_g.second);
}
}
private:
struct HandleHash {
size_t operator()(const Handle<HeapObject>& x) const {