1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_OBJECTS_FEEDBACK_CELL_H_
6 #define V8_OBJECTS_FEEDBACK_CELL_H_
7 
8 #include "src/objects/struct.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 #include "torque-generated/src/objects/feedback-cell-tq.inc"
17 
18 // This is a special cell used to maintain both the link between a
19 // closure and its feedback vector, as well as a way to count the
20 // number of closures created for a certain function per native
21 // context. There's at most one FeedbackCell for each function in
22 // a native context.
23 class FeedbackCell : public TorqueGeneratedFeedbackCell<FeedbackCell, Struct> {
24  public:
25   // Dispatched behavior.
26   DECL_PRINTER(FeedbackCell)
27 
28   static const int kUnalignedSize = kSize;
29   static const int kAlignedSize = RoundUp<kObjectAlignment>(int{kSize});
30 
31   inline void clear_padding();
32   inline void reset_feedback_vector(
33       base::Optional<std::function<void(HeapObject object, ObjectSlot slot,
34                                         HeapObject target)>>
35           gc_notify_updated_slot = base::nullopt);
36   inline void SetInitialInterruptBudget();
37   inline void SetInterruptBudget();
38 
39   // The closure count is encoded in the cell's map, which distinguishes
40   // between zero, one, or many closures. This function records a new closure
41   // creation by updating the map.
42   inline void IncrementClosureCount(Isolate* isolate);
43 
44   using BodyDescriptor =
45       FixedBodyDescriptor<kValueOffset, kInterruptBudgetOffset, kAlignedSize>;
46 
47   TQ_OBJECT_CONSTRUCTORS(FeedbackCell)
48 };
49 
50 }  // namespace internal
51 }  // namespace v8
52 
53 #include "src/objects/object-macros-undef.h"
54 
55 #endif  // V8_OBJECTS_FEEDBACK_CELL_H_
56