From 2799f7fb3d3a2406b1608f0b9bc470ff76ad4ea0 Mon Sep 17 00:00:00 2001 From: reveman Date: Mon, 16 Mar 2015 12:06:21 -0700 Subject: Re-land: base: Implement browser process support for discardable memory. This implements support for in-process discardable memory. Each in-process discardable memory instance is associated with a discardable shared memory segment. This is hopefully efficient enough with the limited use of discardable memory in the browser process. DiscardableSharedMemoryHeap can be used if this is not enough. This also moves the test implementation of the discardable memory allocator into a TestDiscardableMemoryShmemAllocator class and requires tests that use discardable memory to explicitly use this test allocator. Browser tests uses the real discardable memory allocator. BUG=422953,463250 Review URL: https://codereview.chromium.org/1004043002 Cr-Commit-Position: refs/heads/master@{#320764} --- base/test/BUILD.gn | 2 ++ .../test_discardable_memory_shmem_allocator.cc | 40 ++++++++++++++++++++++ .../test/test_discardable_memory_shmem_allocator.h | 28 +++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 base/test/test_discardable_memory_shmem_allocator.cc create mode 100644 base/test/test_discardable_memory_shmem_allocator.h (limited to 'base/test') diff --git a/base/test/BUILD.gn b/base/test/BUILD.gn index 55e710d..f5d2e4c 100644 --- a/base/test/BUILD.gn +++ b/base/test/BUILD.gn @@ -81,6 +81,8 @@ source_set("test_support") { "simple_test_tick_clock.h", "task_runner_test_template.cc", "task_runner_test_template.h", + "test_discardable_memory_shmem_allocator.cc", + "test_discardable_memory_shmem_allocator.h", "test_file_util.cc", "test_file_util.h", "test_file_util_android.cc", diff --git a/base/test/test_discardable_memory_shmem_allocator.cc b/base/test/test_discardable_memory_shmem_allocator.cc new file mode 100644 index 0000000..24185a2 --- /dev/null +++ b/base/test/test_discardable_memory_shmem_allocator.cc @@ -0,0 +1,40 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/test/test_discardable_memory_shmem_allocator.h" + +#include + +namespace base { +namespace { + +class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk { + public: + explicit DiscardableMemoryShmemChunkImpl(size_t size) + : memory_(new uint8_t[size]) {} + + // Overridden from DiscardableMemoryShmemChunk: + bool Lock() override { return false; } + void Unlock() override {} + void* Memory() const override { return memory_.get(); } + + private: + scoped_ptr memory_; +}; + +} // namespace + +TestDiscardableMemoryShmemAllocator::TestDiscardableMemoryShmemAllocator() { +} + +TestDiscardableMemoryShmemAllocator::~TestDiscardableMemoryShmemAllocator() { +} + +scoped_ptr +TestDiscardableMemoryShmemAllocator::AllocateLockedDiscardableMemory( + size_t size) { + return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(size)); +} + +} // namespace base diff --git a/base/test/test_discardable_memory_shmem_allocator.h b/base/test/test_discardable_memory_shmem_allocator.h new file mode 100644 index 0000000..a40960e --- /dev/null +++ b/base/test/test_discardable_memory_shmem_allocator.h @@ -0,0 +1,28 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_TEST_TEST_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ +#define BASE_TEST_TEST_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ + +#include "base/memory/discardable_memory_shmem_allocator.h" + +namespace base { + +class TestDiscardableMemoryShmemAllocator + : public DiscardableMemoryShmemAllocator { + public: + TestDiscardableMemoryShmemAllocator(); + ~TestDiscardableMemoryShmemAllocator() override; + + // Overridden from DiscardableMemoryShmemAllocator: + scoped_ptr AllocateLockedDiscardableMemory( + size_t size) override; + + private: + DISALLOW_COPY_AND_ASSIGN(TestDiscardableMemoryShmemAllocator); +}; + +} // namespace base + +#endif // BASE_TEST_TEST_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_ -- cgit v1.1