Commit f970a97e authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[turbofan] Add limits to the serializer

This CL limits the total number of hints of each type (constants, maps,
etc.) to 50. It also adds a limit to the number of seen functions with
the same SFI and feedback vector to 200. Octane already hits those
limits in DeltaBlue and TypeScript, but that doesn't affect the scores.

Bug: v8:7790
Change-Id: I644519955115c09bfb8ba6d98cf21087b153668d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1975757Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65535}
parent 99d95854
......@@ -2525,6 +2525,11 @@ bool JSHeapBroker::ShouldBeSerializedForCompilation(
void JSHeapBroker::SetSerializedForCompilation(
const SharedFunctionInfoRef& shared, const FeedbackVectorRef& feedback,
const HintsVector& arguments) {
if (serialized_functions_.size() >= kMaxSerializedFunctionsCacheSize) {
TRACE_BROKER_MISSING(this,
"opportunity - serialized functions cache is full.");
return;
}
SerializedFunction function{shared, feedback};
serialized_functions_.insert({function, arguments});
TRACE(this, "Set function " << shared << " with " << feedback
......
......@@ -265,6 +265,7 @@ class V8_EXPORT_PRIVATE JSHeapBroker {
}
};
ZoneMultimap<SerializedFunction, HintsVector> serialized_functions_;
static const size_t kMaxSerializedFunctionsCacheSize = 200;
static const size_t kMinimalRefsBucketCount = 8; // must be power of 2
static const size_t kInitialRefsBucketCount = 1024; // must be power of 2
......
......@@ -60,6 +60,8 @@ class FunctionalSet {
return !(*this == other);
}
size_t Size() const { return data_.Size(); }
using iterator = typename FunctionalList<T>::iterator;
iterator begin() const { return data_.begin(); }
......@@ -99,12 +101,14 @@ using VirtualBoundFunctionsSet =
FunctionalSet<VirtualBoundFunction, std::equal_to<VirtualBoundFunction>>;
struct HintsImpl;
class JSHeapBroker;
class Hints {
public:
Hints() = default; // Empty.
static Hints SingleConstant(Handle<Object> constant, Zone* zone);
static Hints SingleMap(Handle<Map> map, Zone* zone);
static Hints SingleConstant(Handle<Object> constant, Zone* zone,
JSHeapBroker* broker);
static Hints SingleMap(Handle<Map> map, Zone* zone, JSHeapBroker* broker);
// For inspection only.
ConstantsSet constants() const;
......@@ -122,7 +126,7 @@ class Hints {
#endif
Hints Copy(Zone* zone) const; // Shallow.
Hints CopyToParentZone(Zone* zone) const; // Deep.
Hints CopyToParentZone(Zone* zone, JSHeapBroker* broker) const; // Deep.
// As an optimization, empty hints can be represented as {impl_} being
// {nullptr}, i.e., as not having allocated a {HintsImpl} object. As a
......@@ -135,17 +139,20 @@ class Hints {
// Make {this} an alias of {other}.
void Reset(Hints* other, Zone* zone);
void Merge(Hints const& other, Zone* zone);
void Merge(Hints const& other, Zone* zone, JSHeapBroker* broker);
// Destructive updates: if the hints are shared by several registers,
// then the following updates will be seen by all of them:
void AddConstant(Handle<Object> constant, Zone* zone);
void AddMap(Handle<Map> map, Zone* zone, bool check_zone_equality = true);
void AddVirtualClosure(VirtualClosure const& virtual_closure, Zone* zone);
void AddVirtualContext(VirtualContext const& virtual_context, Zone* zone);
void AddConstant(Handle<Object> constant, Zone* zone, JSHeapBroker* broker);
void AddMap(Handle<Map> map, Zone* zone, JSHeapBroker* broker,
bool check_zone_equality = true);
void AddVirtualClosure(VirtualClosure const& virtual_closure, Zone* zone,
JSHeapBroker* broker);
void AddVirtualContext(VirtualContext const& virtual_context, Zone* zone,
JSHeapBroker* broker);
void AddVirtualBoundFunction(VirtualBoundFunction const& bound_function,
Zone* zone);
void Add(Hints const& other, Zone* zone);
Zone* zone, JSHeapBroker* broker);
void Add(Hints const& other, Zone* zone, JSHeapBroker* broker);
private:
friend std::ostream& operator<<(std::ostream&, const Hints& hints);
......@@ -154,7 +161,9 @@ class Hints {
void EnsureAllocated(Zone* zone, bool check_zone_equality = true);
// Helper for Add and Merge.
void Union(Hints const& other);
bool Union(Hints const& other);
static const size_t kMaxHintsSize = 50;
};
using HintsVector = ZoneVector<Hints>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment