LCOV - code coverage report
Current view: top level - src/base - bounded-page-allocator.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 8 37.5 %
Date: 2019-04-17 Functions: 3 6 50.0 %

          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_BASE_BOUNDED_PAGE_ALLOCATOR_H_
       6             : #define V8_BASE_BOUNDED_PAGE_ALLOCATOR_H_
       7             : 
       8             : #include "include/v8-platform.h"
       9             : #include "src/base/platform/mutex.h"
      10             : #include "src/base/region-allocator.h"
      11             : 
      12             : namespace v8 {
      13             : namespace base {
      14             : 
      15             : // This is a v8::PageAllocator implementation that allocates pages within the
      16             : // pre-reserved region of virtual space. This class requires the virtual space
      17             : // to be kept reserved during the lifetime of this object.
      18             : // The main application of bounded page allocator are
      19             : //  - V8 heap pointer compression which requires the whole V8 heap to be
      20             : //    allocated within a contiguous range of virtual address space,
      21             : //  - executable page allocation, which allows to use PC-relative 32-bit code
      22             : //    displacement on certain 64-bit platforms.
      23             : // Bounded page allocator uses other page allocator instance for doing actual
      24             : // page allocations.
      25             : // The implementation is thread-safe.
      26             : class V8_BASE_EXPORT BoundedPageAllocator : public v8::PageAllocator {
      27             :  public:
      28             :   using Address = uintptr_t;
      29             : 
      30             :   BoundedPageAllocator(v8::PageAllocator* page_allocator, Address start,
      31             :                        size_t size, size_t allocate_page_size);
      32      127854 :   ~BoundedPageAllocator() override = default;
      33             : 
      34             :   // These functions are not inlined to avoid https://crbug.com/v8/8275.
      35             :   Address begin() const;
      36             :   size_t size() const;
      37             : 
      38             :   // Returns true if given address is in the range controlled by the bounded
      39             :   // page allocator instance.
      40             :   bool contains(Address address) const {
      41             :     return region_allocator_.contains(address);
      42             :   }
      43             : 
      44      263784 :   size_t AllocatePageSize() override { return allocate_page_size_; }
      45             : 
      46         501 :   size_t CommitPageSize() override { return commit_page_size_; }
      47             : 
      48           0 :   void SetRandomMmapSeed(int64_t seed) override {
      49           0 :     page_allocator_->SetRandomMmapSeed(seed);
      50           0 :   }
      51             : 
      52           0 :   void* GetRandomMmapAddr() override {
      53           0 :     return page_allocator_->GetRandomMmapAddr();
      54             :   }
      55             : 
      56             :   void* AllocatePages(void* hint, size_t size, size_t alignment,
      57             :                       Permission access) override;
      58             : 
      59             :   // Allocates pages at given address, returns true on success.
      60             :   bool AllocatePagesAt(Address address, size_t size, Permission access);
      61             : 
      62             :   bool FreePages(void* address, size_t size) override;
      63             : 
      64             :   bool ReleasePages(void* address, size_t size, size_t new_size) override;
      65             : 
      66             :   bool SetPermissions(void* address, size_t size, Permission access) override;
      67             : 
      68             :   bool DiscardSystemPages(void* address, size_t size) override;
      69             : 
      70             :  private:
      71             :   v8::base::Mutex mutex_;
      72             :   const size_t allocate_page_size_;
      73             :   const size_t commit_page_size_;
      74             :   v8::PageAllocator* const page_allocator_;
      75             :   v8::base::RegionAllocator region_allocator_;
      76             : 
      77             :   DISALLOW_COPY_AND_ASSIGN(BoundedPageAllocator);
      78             : };
      79             : 
      80             : }  // namespace base
      81             : }  // namespace v8
      82             : 
      83             : #endif  // V8_BASE_BOUNDED_PAGE_ALLOCATOR_H_

Generated by: LCOV version 1.10