summaryrefslogtreecommitdiff
path: root/chromium/v8/src/heap/concurrent-allocator.h
blob: 795e37d339ca04ec93270f0ac87a6939370d0951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_CONCURRENT_ALLOCATOR_H_
#define V8_HEAP_CONCURRENT_ALLOCATOR_H_

#include "src/common/globals.h"
#include "src/heap/heap.h"
#include "src/heap/spaces.h"
#include "src/tasks/cancelable-task.h"

namespace v8 {
namespace internal {

class LocalHeap;

class StressConcurrentAllocatorTask : public CancelableTask {
 public:
  explicit StressConcurrentAllocatorTask(Isolate* isolate)
      : CancelableTask(isolate), isolate_(isolate) {}

  void RunInternal() override;

  // Schedules task on background thread
  static void Schedule(Isolate* isolate);

 private:
  Isolate* isolate_;
};

// Concurrent allocator for allocation from background threads/tasks.
// Allocations are served from a TLAB if possible.
class ConcurrentAllocator {
 public:
  static const int kLabSize = 4 * KB;
  static const int kMaxLabSize = 32 * KB;
  static const int kMaxLabObjectSize = 2 * KB;

  explicit ConcurrentAllocator(LocalHeap* local_heap, PagedSpace* space)
      : local_heap_(local_heap),
        space_(space),
        lab_(LocalAllocationBuffer::InvalidBuffer()) {}

  inline AllocationResult Allocate(int object_size,
                                   AllocationAlignment alignment,
                                   AllocationOrigin origin);

  inline Address AllocateOrFail(int object_size, AllocationAlignment alignment,
                                AllocationOrigin origin);

  void FreeLinearAllocationArea();
  void MakeLinearAllocationAreaIterable();
  void MarkLinearAllocationAreaBlack();
  void UnmarkLinearAllocationArea();

 private:
  inline bool EnsureLab(AllocationOrigin origin);
  inline AllocationResult AllocateInLab(int object_size,
                                        AllocationAlignment alignment,
                                        AllocationOrigin origin);

  V8_EXPORT_PRIVATE AllocationResult AllocateOutsideLab(
      int object_size, AllocationAlignment alignment, AllocationOrigin origin);

  V8_EXPORT_PRIVATE Address PerformCollectionAndAllocateAgain(
      int object_size, AllocationAlignment alignment, AllocationOrigin origin);

  LocalHeap* const local_heap_;
  PagedSpace* const space_;
  LocalAllocationBuffer lab_;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_CONCURRENT_ALLOCATOR_H_