[vm] Give functions compiled through Dart_LoadCompilationTrace a non-zero usage counter.
So they survive a few code collection cycles.
Change-Id: Ie447b1bcd1f46f58b8e06f6b4f7bedfa1cf3dd77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96203
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
diff --git a/runtime/vm/compilation_trace.cc b/runtime/vm/compilation_trace.cc
index 4c4db1e..9009e0b 100644
--- a/runtime/vm/compilation_trace.cc
+++ b/runtime/vm/compilation_trace.cc
@@ -302,6 +302,11 @@
if (function.is_abstract()) {
return Object::null();
}
+ // Prevent premature code collection due to major GC during startup.
+ const intptr_t kFakeInitialUsage = 32;
+ if (function.usage_counter() < kFakeInitialUsage) {
+ function.set_usage_counter(kFakeInitialUsage);
+ }
return Compiler::CompileFunction(thread_, function);
}