[vm] Reset closure functions cache when sorting class ids
Hashes of functions depend on the class ids, so cache of the closure
functions should be cleared when class ids are sorted.
This is safe to do because at that point all compiled code is cleared.
TEST=ci
Change-Id: Iaf3a66d1026611fc0a3df3903cb4e09e6d6c4c17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311723
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/class_finalizer.cc b/runtime/vm/class_finalizer.cc
index 8dad452..7dc6d41 100644
--- a/runtime/vm/class_finalizer.cc
+++ b/runtime/vm/class_finalizer.cc
@@ -8,6 +8,7 @@
#include "vm/class_finalizer.h"
#include "vm/canonical_tables.h"
+#include "vm/closure_functions_cache.h"
#include "vm/compiler/jit/compiler.h"
#include "vm/flags.h"
#include "vm/hash_table.h"
@@ -995,6 +996,7 @@
RemapClassIds(old_to_new_cid.get());
RehashTypes(); // Types use cid's as part of their hashes.
IG->RehashConstants(); // Const objects use cid's as part of their hashes.
+ ClosureFunctionsCache::ResetLocked(); // Function hashes depend on cids.
}
class CidRewriteVisitor : public ObjectVisitor {
diff --git a/runtime/vm/closure_functions_cache.cc b/runtime/vm/closure_functions_cache.cc
index add92ff..23dfff9 100644
--- a/runtime/vm/closure_functions_cache.cc
+++ b/runtime/vm/closure_functions_cache.cc
@@ -189,5 +189,16 @@
}
}
}
+void ClosureFunctionsCache::ResetLocked() {
+ auto thread = Thread::Current();
+ auto zone = thread->zone();
+ auto object_store = thread->isolate_group()->object_store();
+ DEBUG_ASSERT(
+ thread->isolate_group()->program_lock()->IsCurrentThreadWriter());
+
+ object_store->set_closure_functions_table(Object::null_array());
+ object_store->set_closure_functions(
+ GrowableObjectArray::Handle(zone, GrowableObjectArray::New()));
+}
} // namespace dart
diff --git a/runtime/vm/closure_functions_cache.h b/runtime/vm/closure_functions_cache.h
index 9991f71..6707386 100644
--- a/runtime/vm/closure_functions_cache.h
+++ b/runtime/vm/closure_functions_cache.h
@@ -59,6 +59,9 @@
// closure functions have been visited.
static void ForAllClosureFunctions(
std::function<bool(const Function&)> callback);
+
+ // Clear the cache of closure functions.
+ static void ResetLocked();
};
} // namespace dart