Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_allocator_android.h" | 5 #include "base/memory/discardable_memory_allocator_android.h" |
| 6 | 6 |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include "base/memory/discardable_memory.h" | 10 #include "base/memory/discardable_memory.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 // The last page of the first ashmem region should be used for this | 264 // The last page of the first ashmem region should be used for this |
| 265 // allocation. | 265 // allocation. |
| 266 scoped_ptr<DiscardableMemory> memory3(allocator_.Allocate(kPageSize)); | 266 scoped_ptr<DiscardableMemory> memory3(allocator_.Allocate(kPageSize)); |
| 267 ASSERT_TRUE(memory3); | 267 ASSERT_TRUE(memory3); |
| 268 WriteToDiscardableMemory(memory3.get(), kPageSize); | 268 WriteToDiscardableMemory(memory3.get(), kPageSize); |
| 269 EXPECT_EQ(memory3->Memory(), static_cast<char*>(memory1->Memory()) + size); | 269 EXPECT_EQ(memory3->Memory(), static_cast<char*>(memory1->Memory()) + size); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(DiscardableMemoryAllocatorTest, | 272 TEST_F(DiscardableMemoryAllocatorTest, |
| 273 HighestAllocatedChunkPointerIsUpdatedWhenHighestChunkGetsSplit) { | 273 HighestAllocatedChunkPointerIsUpdatedWhenHighestChunkGetsSplit) { |
| 274 DiscardableMemoryAllocator allocator_(kAllocatorName, 32 * kPageSize); | |
|
Philippe
2014/03/05 15:36:03
FYI, I just uploaded a patch set removing this (wh
| |
| 275 | |
| 276 // Prevents the ashmem region from getting closed when |memory2| gets freed. | 274 // Prevents the ashmem region from getting closed when |memory2| gets freed. |
| 277 scoped_ptr<DiscardableMemory> memory1(allocator_.Allocate(kPageSize)); | 275 scoped_ptr<DiscardableMemory> memory1(allocator_.Allocate(kPageSize)); |
| 278 ASSERT_TRUE(memory1); | 276 ASSERT_TRUE(memory1); |
| 279 | 277 |
| 280 scoped_ptr<DiscardableMemory> memory2(allocator_.Allocate(4 * kPageSize)); | 278 scoped_ptr<DiscardableMemory> memory2(allocator_.Allocate(4 * kPageSize)); |
| 281 ASSERT_TRUE(memory2); | 279 ASSERT_TRUE(memory2); |
| 282 | 280 |
| 283 memory2.reset(); | 281 memory2.reset(); |
| 284 memory2 = allocator_.Allocate(kPageSize); | 282 memory2 = allocator_.Allocate(kPageSize); |
| 285 // There should now be a free chunk of size 3 * |kPageSize| starting at offset | 283 // There should now be a free chunk of size 3 * |kPageSize| starting at offset |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 296 // Deleting |memory3| (whose size is 4 * |kPageSize|) should result in a merge | 294 // Deleting |memory3| (whose size is 4 * |kPageSize|) should result in a merge |
| 297 // with its previous chunk which is the free chunk of size |3 * kPageSize|. | 295 // with its previous chunk which is the free chunk of size |3 * kPageSize|. |
| 298 memory3.reset(); | 296 memory3.reset(); |
| 299 memory3 = allocator_.Allocate((3 + 4) * kPageSize); | 297 memory3 = allocator_.Allocate((3 + 4) * kPageSize); |
| 300 EXPECT_EQ(memory3->Memory(), | 298 EXPECT_EQ(memory3->Memory(), |
| 301 static_cast<const char*>(memory2->Memory()) + kPageSize); | 299 static_cast<const char*>(memory2->Memory()) + kPageSize); |
| 302 } | 300 } |
| 303 | 301 |
| 304 } // namespace internal | 302 } // namespace internal |
| 305 } // namespace base | 303 } // namespace base |
| OLD | NEW |