OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/discardable_memory_mach.h" | 5 #include "base/memory/discardable_memory_mach.h" |
6 | 6 |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 : memory_(0, 0), bytes_(mach_vm_round_page(bytes)), is_locked_(false) { | 56 : memory_(0, 0), bytes_(mach_vm_round_page(bytes)), is_locked_(false) { |
57 g_manager.Pointer()->Register(this, bytes); | 57 g_manager.Pointer()->Register(this, bytes); |
58 } | 58 } |
59 | 59 |
60 DiscardableMemoryMach::~DiscardableMemoryMach() { | 60 DiscardableMemoryMach::~DiscardableMemoryMach() { |
61 if (is_locked_) | 61 if (is_locked_) |
62 Unlock(); | 62 Unlock(); |
63 g_manager.Pointer()->Unregister(this); | 63 g_manager.Pointer()->Unregister(this); |
64 } | 64 } |
65 | 65 |
66 // static | |
67 void DiscardableMemoryMach::PurgeForTesting() { | |
68 int state = 0; | |
69 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); | |
70 } | |
71 | |
72 bool DiscardableMemoryMach::Initialize() { | 66 bool DiscardableMemoryMach::Initialize() { |
73 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; | 67 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
74 } | 68 } |
75 | 69 |
76 DiscardableMemoryLockStatus DiscardableMemoryMach::Lock() { | 70 DiscardableMemoryLockStatus DiscardableMemoryMach::Lock() { |
77 DCHECK(!is_locked_); | 71 DCHECK(!is_locked_); |
78 | 72 |
79 bool purged = false; | 73 bool purged = false; |
80 if (!g_manager.Pointer()->AcquireLock(this, &purged)) | 74 if (!g_manager.Pointer()->AcquireLock(this, &purged)) |
81 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; | 75 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 ret = vm_protect( | 141 ret = vm_protect( |
148 mach_task_self(), memory_.address(), memory_.size(), FALSE, VM_PROT_NONE); | 142 mach_task_self(), memory_.address(), memory_.size(), FALSE, VM_PROT_NONE); |
149 MACH_DCHECK(ret == KERN_SUCCESS, ret) << "vm_protect"; | 143 MACH_DCHECK(ret == KERN_SUCCESS, ret) << "vm_protect"; |
150 #endif | 144 #endif |
151 } | 145 } |
152 | 146 |
153 void DiscardableMemoryMach::Purge() { | 147 void DiscardableMemoryMach::Purge() { |
154 memory_.reset(); | 148 memory_.reset(); |
155 } | 149 } |
156 | 150 |
157 bool DiscardableMemoryMach::IsMemoryResident() const { | |
158 return true; | |
159 } | |
160 | |
161 } // namespace internal | 151 } // namespace internal |
162 } // namespace base | 152 } // namespace base |
OLD | NEW |