OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 #include "src/heap/array-buffer-tracker.h" | |
6 #include "src/heap/heap.h" | |
7 #include "src/heap/mark-compact.h" | |
8 #include "src/isolate.h" | |
9 | |
10 namespace v8 { | |
11 namespace internal { | |
12 | |
13 template <typename Callback> | |
14 void LocalArrayBufferTracker::Process(Callback callback) { | |
15 JSArrayBuffer* new_buffer = nullptr; | |
16 size_t freed_memory = 0; | |
17 for (TrackingMap::iterator it = live_.begin(); it != live_.end();) { | |
18 switch (callback(it->first, &new_buffer)) { | |
19 case kKeepEntry: | |
20 it++; | |
21 break; | |
22 case kKeepAndUpdateEntry: | |
23 DCHECK_NOT_NULL(new_buffer); | |
24 Page::FromAddress(new_buffer->address()) | |
25 ->local_tracker<Page::kCreateIfNotPresent>() | |
26 ->AddLive(new_buffer, it->second); | |
27 live_.erase(it++); | |
28 break; | |
29 case kRemoveEntry: | |
30 heap_->isolate()->array_buffer_allocator()->Free(it->second.first, | |
31 it->second.second); | |
32 freed_memory += it->second.second; | |
33 live_.erase(it++); | |
34 break; | |
35 default: | |
36 UNREACHABLE(); | |
37 } | |
38 } | |
39 if (freed_memory > 0) { | |
40 heap_->update_amount_of_external_allocated_freed_memory( | |
41 static_cast<intptr_t>(freed_memory)); | |
42 } | |
43 not_yet_discovered_.clear(); | |
44 started_ = false; | |
45 } | |
46 | |
47 template <LocalArrayBufferTracker::LivenessIndicator liveness_indicator> | |
48 void LocalArrayBufferTracker::ScanAndFreeDead() { | |
49 switch (liveness_indicator) { | |
50 case kForwardingPointer: | |
51 Process([](JSArrayBuffer* old_buffer, JSArrayBuffer** new_buffer) { | |
52 MapWord map_word = old_buffer->map_word(); | |
53 if (map_word.IsForwardingAddress()) { | |
54 *new_buffer = JSArrayBuffer::cast(map_word.ToForwardingAddress()); | |
55 return LocalArrayBufferTracker::kKeepAndUpdateEntry; | |
56 } | |
57 return LocalArrayBufferTracker::kRemoveEntry; | |
58 }); | |
59 break; | |
60 case kMarkBit: | |
61 Process([](JSArrayBuffer* old_buffer, JSArrayBuffer**) { | |
62 if (Marking::IsBlackOrGrey(Marking::MarkBitFrom(old_buffer))) { | |
63 return LocalArrayBufferTracker::kKeepEntry; | |
64 } | |
65 return LocalArrayBufferTracker::kRemoveEntry; | |
66 }); | |
67 break; | |
68 default: | |
69 UNREACHABLE(); | |
70 } | |
71 } | |
72 | |
73 } // namespace internal | |
74 } // namespace v8 | |
OLD | NEW |