• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_HEAP_INVALIDATED_SLOTS_INL_H_
6 #define V8_HEAP_INVALIDATED_SLOTS_INL_H_
7 
8 #include <map>
9 
10 #include "src/heap/invalidated-slots.h"
11 #include "src/heap/spaces.h"
12 #include "src/objects/objects-body-descriptors-inl.h"
13 #include "src/objects/objects-body-descriptors.h"
14 #include "src/objects/objects.h"
15 #include "src/utils/allocation.h"
16 
17 namespace v8 {
18 namespace internal {
19 
IsValid(Address slot)20 bool InvalidatedSlotsFilter::IsValid(Address slot) {
21 #ifdef DEBUG
22   DCHECK_LT(slot, sentinel_);
23   // Slots must come in non-decreasing order.
24   DCHECK_LE(last_slot_, slot);
25   last_slot_ = slot;
26 #endif
27   if (slot < invalidated_start_) {
28     return true;
29   }
30 
31   while (slot >= next_invalidated_start_) {
32     NextInvalidatedObject();
33   }
34 
35   HeapObject invalidated_object = HeapObject::FromAddress(invalidated_start_);
36 
37   if (invalidated_size_ == 0) {
38     DCHECK(invalidated_object.map().IsMap());
39     invalidated_size_ = invalidated_object.Size();
40   }
41 
42   int offset = static_cast<int>(slot - invalidated_start_);
43   DCHECK_GT(offset, 0);
44   if (offset < invalidated_size_)
45     return invalidated_object.IsValidSlot(invalidated_object.map(), offset);
46 
47   NextInvalidatedObject();
48   return true;
49 }
50 
NextInvalidatedObject()51 void InvalidatedSlotsFilter::NextInvalidatedObject() {
52   invalidated_start_ = next_invalidated_start_;
53   invalidated_size_ = 0;
54 
55   if (iterator_ == iterator_end_) {
56     next_invalidated_start_ = sentinel_;
57   } else {
58     next_invalidated_start_ = iterator_->address();
59     iterator_++;
60   }
61 }
62 
Free(Address free_start,Address free_end)63 void InvalidatedSlotsCleanup::Free(Address free_start, Address free_end) {
64 #ifdef DEBUG
65   DCHECK_LT(free_start, free_end);
66   // Free regions should come in increasing order and do not overlap
67   DCHECK_LE(last_free_, free_start);
68   last_free_ = free_start;
69 #endif
70 
71   if (iterator_ == iterator_end_) return;
72 
73   // Ignore invalidated objects that start before free region
74   while (invalidated_start_ < free_start) {
75     ++iterator_;
76     NextInvalidatedObject();
77   }
78 
79   // Remove all invalidated objects that start within
80   // free region.
81   while (invalidated_start_ < free_end) {
82     iterator_ = invalidated_slots_->erase(iterator_);
83     NextInvalidatedObject();
84   }
85 }
86 
NextInvalidatedObject()87 void InvalidatedSlotsCleanup::NextInvalidatedObject() {
88   if (iterator_ != iterator_end_) {
89     invalidated_start_ = iterator_->address();
90   } else {
91     invalidated_start_ = sentinel_;
92   }
93 }
94 
95 }  // namespace internal
96 }  // namespace v8
97 
98 #endif  // V8_HEAP_INVALIDATED_SLOTS_INL_H_
99