LCOV - code coverage report
Current view: top level - test/common - assembler-tester.h (source / functions) Hit Total Coverage
Test: app.info Lines: 24 26 92.3 %
Date: 2019-02-19 Functions: 11 12 91.7 %

          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        2474 :   TestingAssemblerBuffer(size_t requested, void* address) {
      17        1237 :     size_t page_size = v8::internal::AllocatePageSize();
      18        1237 :     size_t alloc_size = RoundUp(requested, page_size);
      19        1237 :     CHECK_GE(kMaxInt, alloc_size);
      20        1237 :     size_ = static_cast<int>(alloc_size);
      21             :     buffer_ = static_cast<byte*>(AllocatePages(GetPlatformPageAllocator(),
      22             :                                                address, alloc_size, page_size,
      23        1237 :                                                v8::PageAllocator::kReadWrite));
      24        1237 :     CHECK_NOT_NULL(buffer_);
      25        1237 :   }
      26             : 
      27        2474 :   ~TestingAssemblerBuffer() {
      28        1237 :     CHECK(FreePages(GetPlatformPageAllocator(), buffer_, size_));
      29        2474 :   }
      30             : 
      31        1602 :   byte* start() const override { return buffer_; }
      32             : 
      33         375 :   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         284 :     return ExternalAssemblerBuffer(buffer_, size_);
      41             :   }
      42             : 
      43        1160 :   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        1160 :     FlushInstructionCache(buffer_, size_);
      50             : 
      51             :     bool result = SetPermissions(GetPlatformPageAllocator(), buffer_, size_,
      52        1160 :                                  v8::PageAllocator::kReadExecute);
      53        1160 :     CHECK(result);
      54        1160 :   }
      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             :     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        1237 :   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