• 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/allocation.h"
11 #include "src/heap/invalidated-slots.h"
12 #include "src/heap/spaces.h"
13 #include "src/objects-body-descriptors-inl.h"
14 #include "src/objects-body-descriptors.h"
15 #include "src/objects.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   while (slot >= invalidated_end_) {
28     ++iterator_;
29     if (iterator_ != iterator_end_) {
30       // Invalidated ranges must not overlap.
31       DCHECK_LE(invalidated_end_, iterator_->first->address());
32       invalidated_start_ = iterator_->first->address();
33       invalidated_end_ = invalidated_start_ + iterator_->second;
34       invalidated_object_ = nullptr;
35       invalidated_object_size_ = 0;
36     } else {
37       invalidated_start_ = sentinel_;
38       invalidated_end_ = sentinel_;
39     }
40   }
41   // Now the invalidated region ends after the slot.
42   if (slot < invalidated_start_) {
43     // The invalidated region starts after the slot.
44     return true;
45   }
46   // The invalidated region includes the slot.
47   // Ask the object if the slot is valid.
48   if (invalidated_object_ == nullptr) {
49     invalidated_object_ = HeapObject::FromAddress(invalidated_start_);
50     DCHECK(!invalidated_object_->IsFiller());
51     invalidated_object_size_ =
52         invalidated_object_->SizeFromMap(invalidated_object_->map());
53   }
54   int offset = static_cast<int>(slot - invalidated_start_);
55   DCHECK_GT(offset, 0);
56   DCHECK_LE(invalidated_object_size_,
57             static_cast<int>(invalidated_end_ - invalidated_start_));
58 
59   if (offset >= invalidated_object_size_) {
60     return slots_in_free_space_are_valid_;
61   }
62   return invalidated_object_->IsValidSlot(invalidated_object_->map(), offset);
63 }
64 
65 }  // namespace internal
66 }  // namespace v8
67 
68 #endif  // V8_HEAP_INVALIDATED_SLOTS_INL_H_
69