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_INL_H_
6 #define V8_OBJECTS_FEEDBACK_CELL_INL_H_
7 
8 #include "src/objects/feedback-cell.h"
9 
10 #include "src/heap/heap-write-barrier-inl.h"
11 #include "src/objects/objects-inl.h"
12 #include "src/objects/struct-inl.h"
13 
14 // Has to be the last include (doesn't have include guards):
15 #include "src/objects/object-macros.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 #include "torque-generated/src/objects/feedback-cell-tq-inl.inc"
21 
TQ_OBJECT_CONSTRUCTORS_IMPL(FeedbackCell)22 TQ_OBJECT_CONSTRUCTORS_IMPL(FeedbackCell)
23 
24 void FeedbackCell::clear_padding() {
25   if (FeedbackCell::kAlignedSize == FeedbackCell::kUnalignedSize) return;
26   DCHECK_GE(FeedbackCell::kAlignedSize, FeedbackCell::kUnalignedSize);
27   memset(reinterpret_cast<byte*>(address() + FeedbackCell::kUnalignedSize), 0,
28          FeedbackCell::kAlignedSize - FeedbackCell::kUnalignedSize);
29 }
30 
reset_feedback_vector(base::Optional<std::function<void (HeapObject object,ObjectSlot slot,HeapObject target)>> gc_notify_updated_slot)31 void FeedbackCell::reset_feedback_vector(
32     base::Optional<std::function<void(HeapObject object, ObjectSlot slot,
33                                       HeapObject target)>>
34         gc_notify_updated_slot) {
35   SetInitialInterruptBudget();
36   if (value().IsUndefined() || value().IsClosureFeedbackCellArray()) return;
37 
38   CHECK(value().IsFeedbackVector());
39   ClosureFeedbackCellArray closure_feedback_cell_array =
40       FeedbackVector::cast(value()).closure_feedback_cell_array();
41   set_value(closure_feedback_cell_array);
42   if (gc_notify_updated_slot) {
43     (*gc_notify_updated_slot)(*this, RawField(FeedbackCell::kValueOffset),
44                               closure_feedback_cell_array);
45   }
46 }
47 
SetInitialInterruptBudget()48 void FeedbackCell::SetInitialInterruptBudget() {
49   if (FLAG_lazy_feedback_allocation) {
50     set_interrupt_budget(FLAG_budget_for_feedback_vector_allocation);
51   } else {
52     set_interrupt_budget(FLAG_interrupt_budget);
53   }
54 }
55 
SetInterruptBudget()56 void FeedbackCell::SetInterruptBudget() {
57   set_interrupt_budget(FLAG_interrupt_budget);
58 }
59 
IncrementClosureCount(Isolate * isolate)60 void FeedbackCell::IncrementClosureCount(Isolate* isolate) {
61   ReadOnlyRoots r(isolate);
62   if (map() == r.no_closures_cell_map()) {
63     set_map(r.one_closure_cell_map());
64   } else if (map() == r.one_closure_cell_map()) {
65     set_map(r.many_closures_cell_map());
66   } else {
67     DCHECK(map() == r.many_closures_cell_map());
68   }
69 }
70 
71 }  // namespace internal
72 }  // namespace v8
73 
74 #include "src/objects/object-macros-undef.h"
75 
76 #endif  // V8_OBJECTS_FEEDBACK_CELL_INL_H_
77