LCOV - code coverage report
Current view: top level - test/common - assembler-tester.h (source / functions) Hit Total Coverage
Test: app.info Lines: 27 29 93.1 %
Date: 2019-04-17 Functions: 9 11 81.8 %

          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_TEST_COMMON_ASSEMBLER_TESTER_H_
       6             : #define V8_TEST_COMMON_ASSEMBLER_TESTER_H_
       7             : 
       8             : #include "src/assembler.h"
       9             : #include "src/code-desc.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : 
      14             : class TestingAssemblerBuffer : public AssemblerBuffer {
      15             :  public:
      16         386 :   TestingAssemblerBuffer(size_t requested, void* address) {
      17         193 :     size_t page_size = v8::internal::AllocatePageSize();
      18         193 :     size_t alloc_size = RoundUp(requested, page_size);
      19         193 :     CHECK_GE(kMaxInt, alloc_size);
      20         193 :     size_ = static_cast<int>(alloc_size);
      21         193 :     buffer_ = static_cast<byte*>(AllocatePages(GetPlatformPageAllocator(),
      22             :                                                address, alloc_size, page_size,
      23         193 :                                                v8::PageAllocator::kReadWrite));
      24         193 :     CHECK_NOT_NULL(buffer_);
      25         193 :   }
      26             : 
      27         579 :   ~TestingAssemblerBuffer() {
      28         193 :     CHECK(FreePages(GetPlatformPageAllocator(), buffer_, size_));
      29         386 :   }
      30             : 
      31         487 :   byte* start() const override { return buffer_; }
      32             : 
      33         300 :   int size() const override { return size_; }
      34             : 
      35           0 :   std::unique_ptr<AssemblerBuffer> Grow(int new_size) override {
      36           0 :     FATAL("Cannot grow TestingAssemblerBuffer");
      37             :   }
      38             : 
      39             :   std::unique_ptr<AssemblerBuffer> CreateView() const {
      40         249 :     return ExternalAssemblerBuffer(buffer_, size_);
      41             :   }
      42             : 
      43         131 :   void MakeExecutable() {
      44             :     // Flush the instruction cache as part of making the buffer executable.
      45             :     // Note: we do this before setting permissions to ReadExecute because on
      46             :     // some older ARM kernels there is a bug which causes an access error on
      47             :     // cache flush instructions to trigger access error on non-writable memory.
      48             :     // See https://bugs.chromium.org/p/v8/issues/detail?id=8157
      49         131 :     FlushInstructionCache(buffer_, size_);
      50             : 
      51         131 :     bool result = SetPermissions(GetPlatformPageAllocator(), buffer_, size_,
      52         131 :                                  v8::PageAllocator::kReadExecute);
      53         131 :     CHECK(result);
      54         131 :   }
      55             : 
      56             :   void MakeWritable() {
      57             :     bool result = SetPermissions(GetPlatformPageAllocator(), buffer_, size_,
      58             :                                  v8::PageAllocator::kReadWrite);
      59             :     CHECK(result);
      60             :   }
      61             : 
      62             :   // TODO(wasm): Only needed for the "test-jump-table-assembler.cc" tests.
      63           4 :   void MakeWritableAndExecutable() {
      64           4 :     bool result = SetPermissions(GetPlatformPageAllocator(), buffer_, size_,
      65           4 :                                  v8::PageAllocator::kReadWriteExecute);
      66           4 :     CHECK(result);
      67           4 :   }
      68             : 
      69             :  private:
      70             :   byte* buffer_;
      71             :   int size_;
      72             : };
      73             : 
      74             : static inline std::unique_ptr<TestingAssemblerBuffer> AllocateAssemblerBuffer(
      75             :     size_t requested = v8::internal::AssemblerBase::kMinimalBufferSize,
      76             :     void* address = nullptr) {
      77         193 :   return base::make_unique<TestingAssemblerBuffer>(requested, address);
      78             : }
      79             : 
      80             : }  // namespace internal
      81             : }  // namespace v8
      82             : 
      83             : #endif  // V8_TEST_COMMON_ASSEMBLER_TESTER_H_

Generated by: LCOV version 1.10