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