Commit 073fe47b authored by reveman's avatar reveman Committed by Commit bot

base: Remove DiscardableMemoryMach.

Remove unused DiscardableMemory implementation.

BUG=442945,422953

Review URL: https://codereview.chromium.org/963233003

Cr-Commit-Position: refs/heads/master@{#320171}
parent 988070a5
...@@ -733,10 +733,6 @@ component("base") { ...@@ -733,10 +733,6 @@ component("base") {
# Mac. # Mac.
if (is_mac) { if (is_mac) {
sources += [
"memory/discardable_memory_mach.cc",
"memory/discardable_memory_mach.h",
]
sources -= [ sources -= [
"native_library_posix.cc", "native_library_posix.cc",
"strings/sys_string_conversions_posix.cc", "strings/sys_string_conversions_posix.cc",
......
...@@ -969,10 +969,6 @@ ...@@ -969,10 +969,6 @@
], ],
}], }],
['(OS == "mac" or OS == "ios") and >(nacl_untrusted_build)==0', { ['(OS == "mac" or OS == "ios") and >(nacl_untrusted_build)==0', {
'sources': [
'memory/discardable_memory_mach.cc',
'memory/discardable_memory_mach.h',
],
'sources/': [ 'sources/': [
['exclude', '^files/file_path_watcher_stub\\.cc$'], ['exclude', '^files/file_path_watcher_stub\\.cc$'],
['exclude', '^base_paths_posix\\.cc$'], ['exclude', '^base_paths_posix\\.cc$'],
......
...@@ -14,7 +14,6 @@ const struct TypeNamePair { ...@@ -14,7 +14,6 @@ const struct TypeNamePair {
DiscardableMemoryType type; DiscardableMemoryType type;
const char* name; const char* name;
} kTypeNamePairs[] = { } kTypeNamePairs[] = {
{ DISCARDABLE_MEMORY_TYPE_MACH, "mach" },
{ DISCARDABLE_MEMORY_TYPE_SHMEM, "shmem" } { DISCARDABLE_MEMORY_TYPE_SHMEM, "shmem" }
}; };
......
...@@ -17,7 +17,6 @@ namespace base { ...@@ -17,7 +17,6 @@ namespace base {
enum DiscardableMemoryType { enum DiscardableMemoryType {
DISCARDABLE_MEMORY_TYPE_NONE, DISCARDABLE_MEMORY_TYPE_NONE,
DISCARDABLE_MEMORY_TYPE_MACH,
DISCARDABLE_MEMORY_TYPE_SHMEM DISCARDABLE_MEMORY_TYPE_SHMEM
}; };
......
...@@ -31,7 +31,6 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( ...@@ -31,7 +31,6 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
return memory.Pass(); return memory.Pass();
} }
case DISCARDABLE_MEMORY_TYPE_NONE: case DISCARDABLE_MEMORY_TYPE_NONE:
case DISCARDABLE_MEMORY_TYPE_MACH:
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
......
...@@ -31,7 +31,6 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( ...@@ -31,7 +31,6 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
return memory.Pass(); return memory.Pass();
} }
case DISCARDABLE_MEMORY_TYPE_NONE: case DISCARDABLE_MEMORY_TYPE_NONE:
case DISCARDABLE_MEMORY_TYPE_MACH:
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include "base/memory/discardable_memory.h" #include "base/memory/discardable_memory.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/discardable_memory_mach.h"
#include "base/memory/discardable_memory_manager.h"
#include "base/memory/discardable_memory_shmem.h" #include "base/memory/discardable_memory_shmem.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -16,8 +14,7 @@ namespace base { ...@@ -16,8 +14,7 @@ namespace base {
void DiscardableMemory::GetSupportedTypes( void DiscardableMemory::GetSupportedTypes(
std::vector<DiscardableMemoryType>* types) { std::vector<DiscardableMemoryType>* types) {
const DiscardableMemoryType supported_types[] = { const DiscardableMemoryType supported_types[] = {
DISCARDABLE_MEMORY_TYPE_SHMEM, DISCARDABLE_MEMORY_TYPE_SHMEM
DISCARDABLE_MEMORY_TYPE_MACH
}; };
types->assign(supported_types, supported_types + arraysize(supported_types)); types->assign(supported_types, supported_types + arraysize(supported_types));
} }
...@@ -26,14 +23,6 @@ void DiscardableMemory::GetSupportedTypes( ...@@ -26,14 +23,6 @@ void DiscardableMemory::GetSupportedTypes(
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
DiscardableMemoryType type, size_t size) { DiscardableMemoryType type, size_t size) {
switch (type) { switch (type) {
case DISCARDABLE_MEMORY_TYPE_MACH: {
scoped_ptr<internal::DiscardableMemoryMach> memory(
new internal::DiscardableMemoryMach(size));
if (!memory->Initialize())
return nullptr;
return memory.Pass();
}
case DISCARDABLE_MEMORY_TYPE_SHMEM: { case DISCARDABLE_MEMORY_TYPE_SHMEM: {
scoped_ptr<internal::DiscardableMemoryShmem> memory( scoped_ptr<internal::DiscardableMemoryShmem> memory(
new internal::DiscardableMemoryShmem(size)); new internal::DiscardableMemoryShmem(size));
......
// Copyright 2014 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/memory/discardable_memory_mach.h"
#include <mach/mach.h>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/mac/mach_logging.h"
namespace base {
namespace {
// For Mach, have the DiscardableMemoryManager trigger userspace eviction when
// address space usage gets too high (e.g. 512 MBytes).
const size_t kMachMemoryLimit = 512 * 1024 * 1024;
// internal::DiscardableMemoryManager has an explicit constructor that takes
// a number of memory limit parameters. The LeakyLazyInstanceTraits doesn't
// handle the case. Thus, we need our own class here.
struct DiscardableMemoryManagerLazyInstanceTraits {
// Leaky as discardable memory clients can use this after the exit handler
// has been called.
static const bool kRegisterOnExit = false;
#ifndef NDEBUG
static const bool kAllowedToAccessOnNonjoinableThread = true;
#endif
static internal::DiscardableMemoryManager* New(void* instance) {
return new (instance) internal::DiscardableMemoryManager(
kMachMemoryLimit, kMachMemoryLimit, TimeDelta::Max());
}
static void Delete(internal::DiscardableMemoryManager* instance) {
instance->~DiscardableMemoryManager();
}
};
LazyInstance<internal::DiscardableMemoryManager,
DiscardableMemoryManagerLazyInstanceTraits>
g_manager = LAZY_INSTANCE_INITIALIZER;
// The VM subsystem allows tagging of memory and 240-255 is reserved for
// application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic
// weight of ~52).
const int kDiscardableMemoryTag = VM_MAKE_TAG(252);
} // namespace
namespace internal {
DiscardableMemoryMach::DiscardableMemoryMach(size_t bytes)
: memory_(0, 0), bytes_(mach_vm_round_page(bytes)), is_locked_(false) {
g_manager.Pointer()->Register(this, bytes);
}
DiscardableMemoryMach::~DiscardableMemoryMach() {
if (is_locked_)
Unlock();
g_manager.Pointer()->Unregister(this);
}
bool DiscardableMemoryMach::Initialize() {
return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
}
DiscardableMemoryLockStatus DiscardableMemoryMach::Lock() {
DCHECK(!is_locked_);
bool purged = false;
if (!g_manager.Pointer()->AcquireLock(this, &purged))
return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
is_locked_ = true;
return purged ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
: DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
}
void DiscardableMemoryMach::Unlock() {
DCHECK(is_locked_);
g_manager.Pointer()->ReleaseLock(this);
is_locked_ = false;
}
void* DiscardableMemoryMach::Memory() const {
DCHECK(is_locked_);
return reinterpret_cast<void*>(memory_.address());
}
bool DiscardableMemoryMach::AllocateAndAcquireLock() {
kern_return_t ret;
bool persistent;
if (!memory_.size()) {
vm_address_t address = 0;
ret = vm_allocate(
mach_task_self(),
&address,
bytes_,
VM_FLAGS_ANYWHERE | VM_FLAGS_PURGABLE | kDiscardableMemoryTag);
MACH_CHECK(ret == KERN_SUCCESS, ret) << "vm_allocate";
memory_.reset(address, bytes_);
// When making a fresh allocation, it's impossible for |persistent| to
// be true.
persistent = false;
} else {
// |persistent| will be reset to false below if appropriate, but when
// reusing an existing allocation, it's possible for it to be true.
persistent = true;
#if !defined(NDEBUG)
ret = vm_protect(mach_task_self(),
memory_.address(),
memory_.size(),
FALSE,
VM_PROT_DEFAULT);
MACH_DCHECK(ret == KERN_SUCCESS, ret) << "vm_protect";
#endif
}
int state = VM_PURGABLE_NONVOLATILE;
ret = vm_purgable_control(
mach_task_self(), memory_.address(), VM_PURGABLE_SET_STATE, &state);
MACH_CHECK(ret == KERN_SUCCESS, ret) << "vm_purgable_control";
if (state & VM_PURGABLE_EMPTY)
persistent = false;
return persistent;
}
void DiscardableMemoryMach::ReleaseLock() {
int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT;
kern_return_t ret = vm_purgable_control(
mach_task_self(), memory_.address(), VM_PURGABLE_SET_STATE, &state);
MACH_CHECK(ret == KERN_SUCCESS, ret) << "vm_purgable_control";
#if !defined(NDEBUG)
ret = vm_protect(
mach_task_self(), memory_.address(), memory_.size(), FALSE, VM_PROT_NONE);
MACH_DCHECK(ret == KERN_SUCCESS, ret) << "vm_protect";
#endif
}
void DiscardableMemoryMach::Purge() {
memory_.reset();
}
} // namespace internal
} // namespace base
// Copyright 2014 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_MEMORY_DISCARDABLE_MEMORY_MACH_H_
#define BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_
#include "base/memory/discardable_memory.h"
#include "base/mac/scoped_mach_vm.h"
#include "base/memory/discardable_memory_manager.h"
namespace base {
namespace internal {
class DiscardableMemoryMach
: public DiscardableMemory,
public internal::DiscardableMemoryManagerAllocation {
public:
explicit DiscardableMemoryMach(size_t bytes);
~DiscardableMemoryMach() override;
bool Initialize();
// Overridden from DiscardableMemory:
DiscardableMemoryLockStatus Lock() override;
void Unlock() override;
void* Memory() const override;
// Overridden from internal::DiscardableMemoryManagerAllocation:
bool AllocateAndAcquireLock() override;
void ReleaseLock() override;
void Purge() override;
private:
mac::ScopedMachVM memory_;
const size_t bytes_;
bool is_locked_;
DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMach);
};
} // namespace internal
} // namespace base
#endif // BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_
...@@ -38,12 +38,12 @@ TEST_P(DiscardableMemoryTest, IsNamed) { ...@@ -38,12 +38,12 @@ TEST_P(DiscardableMemoryTest, IsNamed) {
} }
bool IsNativeType(DiscardableMemoryType type) { bool IsNativeType(DiscardableMemoryType type) {
return
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// SHMEM is backed by native discardable memory on Android. // SHMEM is backed by native discardable memory on Android.
type == DISCARDABLE_MEMORY_TYPE_SHMEM || return type == DISCARDABLE_MEMORY_TYPE_SHMEM;
#else
return false;
#endif #endif
type == DISCARDABLE_MEMORY_TYPE_MACH;
} }
TEST_P(DiscardableMemoryTest, SupportedNatively) { TEST_P(DiscardableMemoryTest, SupportedNatively) {
......
...@@ -31,7 +31,6 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( ...@@ -31,7 +31,6 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
return memory.Pass(); return memory.Pass();
} }
case DISCARDABLE_MEMORY_TYPE_NONE: case DISCARDABLE_MEMORY_TYPE_NONE:
case DISCARDABLE_MEMORY_TYPE_MACH:
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
......
...@@ -778,7 +778,6 @@ ...@@ -778,7 +778,6 @@
}], }],
['OS=="mac" or OS=="ios"', { ['OS=="mac" or OS=="ios"', {
'native_discardable_memory%': 1,
'native_memory_pressure_signals%': 1, 'native_memory_pressure_signals%': 1,
}], }],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment