forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a DiscardableMemoryType enum and a function that can be used to select what type of discardable memory to use. This is generally useful for debugging purposes and when evaluating the performance of one implementation vs another. The unit test framework for discardable memory is improved slightly by testing every supported type on each platform rather then just the one specific type. Furthermore, it allows us to expose ashmem based discardable memory on ChromeOS in about:flags before we make it default. No change in behavior unless the new --use-discardable-memory=type switch is used. BUG=327516 TEST=base_unitttest --gtest_filter=DiscardableMemory* TBR=tomhudson@google.com Review URL: https://codereview.chromium.org/114923005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243532 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
reveman@chromium.org
committed
Jan 8, 2014
1 parent
5e14a1e
commit ed1cca4
Showing
21 changed files
with
407 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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.h" | ||
|
||
#include "base/lazy_instance.h" | ||
#include "base/logging.h" | ||
|
||
namespace base { | ||
namespace { | ||
|
||
const struct TypeNamePair { | ||
DiscardableMemoryType type; | ||
const char* name; | ||
} kTypeNamePairs[] = { | ||
{ DISCARDABLE_MEMORY_TYPE_ANDROID, "android" }, | ||
{ DISCARDABLE_MEMORY_TYPE_MAC, "mac" }, | ||
{ DISCARDABLE_MEMORY_TYPE_EMULATED, "emulated" } | ||
}; | ||
|
||
DiscardableMemoryType g_preferred_type = DISCARDABLE_MEMORY_TYPE_NONE; | ||
|
||
struct DefaultPreferredType { | ||
DefaultPreferredType() : value(DISCARDABLE_MEMORY_TYPE_NONE) { | ||
std::vector<DiscardableMemoryType> supported_types; | ||
DiscardableMemory::GetSupportedTypes(&supported_types); | ||
DCHECK(!supported_types.empty()); | ||
value = supported_types[0]; | ||
} | ||
DiscardableMemoryType value; | ||
}; | ||
LazyInstance<DefaultPreferredType>::Leaky g_default_preferred_type = | ||
LAZY_INSTANCE_INITIALIZER; | ||
|
||
} // namespace | ||
|
||
// static | ||
DiscardableMemoryType DiscardableMemory::GetNamedType( | ||
const std::string& name) { | ||
for (size_t i = 0; i < arraysize(kTypeNamePairs); ++i) { | ||
if (name == kTypeNamePairs[i].name) | ||
return kTypeNamePairs[i].type; | ||
} | ||
|
||
return DISCARDABLE_MEMORY_TYPE_NONE; | ||
} | ||
|
||
// static | ||
const char* DiscardableMemory::GetTypeName(DiscardableMemoryType type) { | ||
for (size_t i = 0; i < arraysize(kTypeNamePairs); ++i) { | ||
if (type == kTypeNamePairs[i].type) | ||
return kTypeNamePairs[i].name; | ||
} | ||
|
||
return "unknown"; | ||
} | ||
|
||
// static | ||
void DiscardableMemory::SetPreferredType(DiscardableMemoryType type) { | ||
// NONE is a reserved value and not a valid default type. | ||
DCHECK_NE(DISCARDABLE_MEMORY_TYPE_NONE, type); | ||
|
||
// Make sure this function is only called once before the first call | ||
// to GetPreferredType(). | ||
DCHECK_EQ(DISCARDABLE_MEMORY_TYPE_NONE, g_preferred_type); | ||
|
||
g_preferred_type = type; | ||
} | ||
|
||
// static | ||
DiscardableMemoryType DiscardableMemory::GetPreferredType() { | ||
if (g_preferred_type == DISCARDABLE_MEMORY_TYPE_NONE) | ||
g_preferred_type = g_default_preferred_type.Get().value; | ||
|
||
return g_preferred_type; | ||
} | ||
|
||
// static | ||
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemory( | ||
size_t size) { | ||
return CreateLockedMemoryWithType(GetPreferredType(), size); | ||
} | ||
|
||
} // namespace base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.