Line data Source code
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_ARRAY_BUFFER_COLLECTOR_H_
6 : #define V8_HEAP_ARRAY_BUFFER_COLLECTOR_H_
7 :
8 : #include <vector>
9 :
10 : #include "src/base/platform/mutex.h"
11 : #include "src/objects/js-array-buffer.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 : class Heap;
17 :
18 : // To support background processing of array buffer backing stores, we process
19 : // array buffers using the ArrayBufferTracker class. The ArrayBufferCollector
20 : // keeps track of garbage backing stores so that they can be freed on a
21 : // background thread.
22 : class ArrayBufferCollector {
23 : public:
24 62422 : explicit ArrayBufferCollector(Heap* heap) : heap_(heap) {}
25 :
26 62406 : ~ArrayBufferCollector() { PerformFreeAllocations(); }
27 :
28 : // These allocations will be either
29 : // - freed immediately when under memory pressure, or
30 : // - queued for freeing in FreeAllocations() or during tear down.
31 : //
32 : // FreeAllocations() potentially triggers a background task for processing.
33 : void QueueOrFreeGarbageAllocations(
34 : std::vector<JSArrayBuffer::Allocation> allocations);
35 :
36 : // Calls FreeAllocations() on a background thread.
37 : void FreeAllocations();
38 :
39 : private:
40 : class FreeingTask;
41 :
42 : // Begin freeing the allocations added through QueueOrFreeGarbageAllocations.
43 : // Also called by TearDown.
44 : void PerformFreeAllocations();
45 :
46 : Heap* const heap_;
47 : base::Mutex allocations_mutex_;
48 : std::vector<std::vector<JSArrayBuffer::Allocation>> allocations_;
49 : };
50 :
51 : } // namespace internal
52 : } // namespace v8
53 :
54 : #endif // V8_HEAP_ARRAY_BUFFER_COLLECTOR_H_
|