Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: base/memory/discardable_memory_mac.cc

Issue 15650016: [Not for review] Discardable memory emulation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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.h" 5 #include "base/memory/discardable_memory.h"
6 6
7 #include <mach/mach.h> 7 #include <mach/mach.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 namespace { 13 namespace {
14 14
15 // The VM subsystem allows tagging of memory and 240-255 is reserved for 15 // The VM subsystem allows tagging of memory and 240-255 is reserved for
16 // application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic 16 // application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic
17 // weight of ~52). 17 // weight of ~52).
18 const int kDiscardableMemoryTag = VM_MAKE_TAG(252); 18 const int kDiscardableMemoryTag = VM_MAKE_TAG(252);
19 19
20 } // namespace 20 } // namespace
21 21
22 // static
23 bool DiscardableMemory::Supported() {
24 return true;
25 }
26
27 DiscardableMemory::~DiscardableMemory() { 22 DiscardableMemory::~DiscardableMemory() {
28 if (memory_) { 23 if (memory_) {
29 vm_deallocate(mach_task_self(), 24 vm_deallocate(mach_task_self(),
30 reinterpret_cast<vm_address_t>(memory_), 25 reinterpret_cast<vm_address_t>(memory_),
31 size_); 26 size_);
32 } 27 }
33 } 28 }
34 29
35 bool DiscardableMemory::InitializeAndLock(size_t size) { 30 bool DiscardableMemory::InitializeAndLock(size_t size) {
36 DCHECK(!memory_); 31 DCHECK(!memory_);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return true; 88 return true;
94 } 89 }
95 90
96 // static 91 // static
97 void DiscardableMemory::PurgeForTesting() { 92 void DiscardableMemory::PurgeForTesting() {
98 int state = 0; 93 int state = 0;
99 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); 94 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state);
100 } 95 }
101 96
102 } // namespace base 97 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698