Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: src/heap/array-buffer-tracker.h

Issue 2870683003: [heap] Factor out marking state of array buffer tracker (Closed)
Patch Set: Get MarkingState out of thin air Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/heap/array-buffer-tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_HEAP_ARRAY_BUFFER_TRACKER_H_ 5 #ifndef V8_HEAP_ARRAY_BUFFER_TRACKER_H_
6 #define V8_HEAP_ARRAY_BUFFER_TRACKER_H_ 6 #define V8_HEAP_ARRAY_BUFFER_TRACKER_H_
7 7
8 #include <unordered_map> 8 #include <unordered_map>
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
11 #include "src/base/platform/mutex.h" 11 #include "src/base/platform/mutex.h"
12 #include "src/globals.h" 12 #include "src/globals.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 class Heap; 17 class Heap;
18 class JSArrayBuffer; 18 class JSArrayBuffer;
19 class MarkingState;
19 class Page; 20 class Page;
20 21
21 class ArrayBufferTracker : public AllStatic { 22 class ArrayBufferTracker : public AllStatic {
22 public: 23 public:
23 enum ProcessingMode { 24 enum ProcessingMode {
24 kUpdateForwardedRemoveOthers, 25 kUpdateForwardedRemoveOthers,
25 kUpdateForwardedKeepOthers, 26 kUpdateForwardedKeepOthers,
26 }; 27 };
27 28
28 // The following methods are used to track raw C++ pointers to externally 29 // The following methods are used to track raw C++ pointers to externally
29 // allocated memory used as backing store in live array buffers. 30 // allocated memory used as backing store in live array buffers.
30 31
31 // Register/unregister a new JSArrayBuffer |buffer| for tracking. Guards all 32 // Register/unregister a new JSArrayBuffer |buffer| for tracking. Guards all
32 // access to the tracker by taking the page lock for the corresponding page. 33 // access to the tracker by taking the page lock for the corresponding page.
33 inline static void RegisterNew(Heap* heap, JSArrayBuffer* buffer); 34 inline static void RegisterNew(Heap* heap, JSArrayBuffer* buffer);
34 inline static void Unregister(Heap* heap, JSArrayBuffer* buffer); 35 inline static void Unregister(Heap* heap, JSArrayBuffer* buffer);
35 36
36 // Frees all backing store pointers for dead JSArrayBuffers in new space. 37 // Frees all backing store pointers for dead JSArrayBuffers in new space.
37 // Does not take any locks and can only be called during Scavenge. 38 // Does not take any locks and can only be called during Scavenge.
38 static void FreeDeadInNewSpace(Heap* heap); 39 static void FreeDeadInNewSpace(Heap* heap);
39 40
40 // Frees all backing store pointers for dead JSArrayBuffer on a given page. 41 // Frees all backing store pointers for dead JSArrayBuffer on a given page.
41 // Requires marking information to be present. Requires the page lock to be 42 // Requires marking information to be present. Requires the page lock to be
42 // taken by the caller. 43 // taken by the caller.
43 static void FreeDead(Page* page); 44 static void FreeDead(Page* page, const MarkingState& marking_state);
44 45
45 // Frees all remaining, live or dead, array buffers on a page. Only useful 46 // Frees all remaining, live or dead, array buffers on a page. Only useful
46 // during tear down. 47 // during tear down.
47 static void FreeAll(Page* page); 48 static void FreeAll(Page* page);
48 49
49 // Processes all array buffers on a given page. |mode| specifies the action 50 // Processes all array buffers on a given page. |mode| specifies the action
50 // to perform on the buffers. Returns whether the tracker is empty or not. 51 // to perform on the buffers. Returns whether the tracker is empty or not.
51 static bool ProcessBuffers(Page* page, ProcessingMode mode); 52 static bool ProcessBuffers(Page* page, ProcessingMode mode);
52 53
53 // Returns whether a buffer is currently tracked. 54 // Returns whether a buffer is currently tracked.
(...skipping 10 matching lines...) Expand all
64 65
65 enum CallbackResult { kKeepEntry, kUpdateEntry, kRemoveEntry }; 66 enum CallbackResult { kKeepEntry, kUpdateEntry, kRemoveEntry };
66 enum FreeMode { kFreeDead, kFreeAll }; 67 enum FreeMode { kFreeDead, kFreeAll };
67 68
68 explicit LocalArrayBufferTracker(Heap* heap) : heap_(heap) {} 69 explicit LocalArrayBufferTracker(Heap* heap) : heap_(heap) {}
69 ~LocalArrayBufferTracker(); 70 ~LocalArrayBufferTracker();
70 71
71 inline void Add(Key key, const Value& value); 72 inline void Add(Key key, const Value& value);
72 inline Value Remove(Key key); 73 inline Value Remove(Key key);
73 74
74 // Frees up array buffers determined by |free_mode|. 75 // Frees up array buffers.
75 template <FreeMode free_mode> 76 //
76 void Free(); 77 // Sample usage:
78 // Free([](HeapObject* array_buffer) {
79 // if (should_free_internal(array_buffer)) return true;
80 // return false;
81 // });
82 template <typename Callback>
83 void Free(Callback should_free);
77 84
78 // Processes buffers one by one. The CallbackResult of the callback decides 85 // Processes buffers one by one. The CallbackResult of the callback decides
79 // what action to take on the buffer. 86 // what action to take on the buffer.
80 // 87 //
81 // Callback should be of type: 88 // Callback should be of type:
82 // CallbackResult fn(JSArrayBuffer* buffer, JSArrayBuffer** new_buffer); 89 // CallbackResult fn(JSArrayBuffer* buffer, JSArrayBuffer** new_buffer);
83 template <typename Callback> 90 template <typename Callback>
84 void Process(Callback callback); 91 void Process(Callback callback);
85 92
86 bool IsEmpty() { return array_buffers_.empty(); } 93 bool IsEmpty() { return array_buffers_.empty(); }
87 94
88 bool IsTracked(Key key) { 95 bool IsTracked(Key key) {
89 return array_buffers_.find(key) != array_buffers_.end(); 96 return array_buffers_.find(key) != array_buffers_.end();
90 } 97 }
91 98
92 private: 99 private:
93 typedef std::unordered_map<Key, Value> TrackingData; 100 typedef std::unordered_map<Key, Value> TrackingData;
94 101
95 Heap* heap_; 102 Heap* heap_;
96 TrackingData array_buffers_; 103 TrackingData array_buffers_;
97 }; 104 };
98 105
99 } // namespace internal 106 } // namespace internal
100 } // namespace v8 107 } // namespace v8
101 #endif // V8_HEAP_ARRAY_BUFFER_TRACKER_H_ 108 #endif // V8_HEAP_ARRAY_BUFFER_TRACKER_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap/array-buffer-tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698