Line data Source code
1 : // Copyright 2018 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_ISOLATE_ALLOCATOR_H_
6 : #define V8_ISOLATE_ALLOCATOR_H_
7 :
8 : #include "src/allocation.h"
9 : #include "src/base/bounded-page-allocator.h"
10 : #include "src/base/page-allocator.h"
11 : #include "src/globals.h"
12 :
13 : namespace v8 {
14 :
15 : // Forward declarations.
16 : namespace base {
17 : class BoundedPageAllocator;
18 : }
19 :
20 : namespace internal {
21 :
22 : // IsolateAllocator object is responsible for allocating memory for one (!)
23 : // Isolate object. Depending on the allocation mode the memory can be allocated
24 : // 1) in the C++ heap (when pointer compression is disabled)
25 : // 2) in a proper part of a properly aligned region of a reserved address space
26 : // (when pointer compression is enabled).
27 : //
28 : // Isolate::New() first creates IsolateAllocator object which allocates the
29 : // memory and then it constructs Isolate object in this memory. Once it's done
30 : // the Isolate object takes ownership of the IsolateAllocator object to keep
31 : // the memory alive.
32 : // Isolate::Delete() takes care of the proper order of the objects destruction.
33 : class V8_EXPORT_PRIVATE IsolateAllocator final {
34 : public:
35 : explicit IsolateAllocator(IsolateAllocationMode mode);
36 : ~IsolateAllocator();
37 :
38 : void* isolate_memory() const { return isolate_memory_; }
39 :
40 : v8::PageAllocator* page_allocator() const { return page_allocator_; }
41 :
42 4 : IsolateAllocationMode mode() {
43 : return reservation_.IsReserved() ? IsolateAllocationMode::kInV8Heap
44 4 : : IsolateAllocationMode::kInCppHeap;
45 : }
46 :
47 : private:
48 : Address InitReservation();
49 : void CommitPagesForIsolate(Address heap_base);
50 :
51 : // The allocated memory for Isolate instance.
52 : void* isolate_memory_ = nullptr;
53 : v8::PageAllocator* page_allocator_ = nullptr;
54 : std::unique_ptr<base::BoundedPageAllocator> page_allocator_instance_;
55 : VirtualMemory reservation_;
56 :
57 : DISALLOW_COPY_AND_ASSIGN(IsolateAllocator);
58 : };
59 :
60 : } // namespace internal
61 : } // namespace v8
62 :
63 : #endif // V8_ISOLATE_ALLOCATOR_H_
|