Index: base/allocator/partition_allocator/partition_alloc_unittest.cc |
diff --git a/third_party/WebKit/Source/wtf/allocator/PartitionAllocTest.cpp b/base/allocator/partition_allocator/partition_alloc_unittest.cc |
similarity index 97% |
rename from third_party/WebKit/Source/wtf/allocator/PartitionAllocTest.cpp |
rename to base/allocator/partition_allocator/partition_alloc_unittest.cc |
index 589d6e90d287341045e860752543924ae7a8506d..4a223418a3513c309761a78006fd63b90e13eed8 100644 |
--- a/third_party/WebKit/Source/wtf/allocator/PartitionAllocTest.cpp |
+++ b/base/allocator/partition_allocator/partition_alloc_unittest.cc |
@@ -1,45 +1,18 @@ |
-/* |
- * Copyright (C) 2013 Google Inc. All rights reserved. |
- * |
- * Redistribution and use in source and binary forms, with or without |
- * modification, are permitted provided that the following conditions are |
- * met: |
- * |
- * * Redistributions of source code must retain the above copyright |
- * notice, this list of conditions and the following disclaimer. |
- * * Redistributions in binary form must reproduce the above |
- * copyright notice, this list of conditions and the following disclaimer |
- * in the documentation and/or other materials provided with the |
- * distribution. |
- * * Neither the name of Google Inc. nor the names of its |
- * contributors may be used to endorse or promote products derived from |
- * this software without specific prior written permission. |
- * |
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- */ |
- |
-#include "wtf/allocator/PartitionAlloc.h" |
+// Copyright (c) 2013 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/allocator/partition_allocator/partition_alloc.h" |
-#include "testing/gtest/include/gtest/gtest.h" |
-#include "wtf/BitwiseOperations.h" |
-#include "wtf/CPU.h" |
-#include "wtf/PtrUtil.h" |
-#include "wtf/Vector.h" |
-#include <memory> |
#include <stdlib.h> |
#include <string.h> |
-#if OS(POSIX) |
+#include <memory> |
+ |
+#include "base/bits.h" |
Primiano Tucci (use gerrit)
2016/11/28 12:06:50
+build_config.h
palmer
2016/12/01 00:48:24
Done.
|
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#if defined(OS_POSIX) |
#include <sys/mman.h> |
#include <sys/resource.h> |
#include <sys/time.h> |
@@ -47,28 +20,43 @@ |
#ifndef MAP_ANONYMOUS |
#define MAP_ANONYMOUS MAP_ANON |
#endif |
-#endif // OS(POSIX) |
+#endif // defined(OSPOSIX) |
#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
-namespace WTF { |
+namespace base { |
namespace { |
+// TODO(palmer): Remove these if possible. |
Primiano Tucci (use gerrit)
2016/11/28 12:06:50
Well they seem already commented out. Removing the
palmer
2016/12/01 00:48:24
Done.
|
+// using base::SizeSpecificPartitionAllocator; |
+// using base::PartitionAllocatorGeneric; |
+// using base::PartitionRoot; |
+// using base::partitionAllocInit; |
+// using base::partitionAllocShutdown; |
+// using base::partitionAlloc; |
+// using base::partitionFree; |
+// using base::partitionAllocGeneric; |
+// using base::partitionFreeGeneric; |
+// using base::partitionReallocGeneric; |
+// using base::partitionAllocActualSize; |
+// using base::partitionAllocSupportsGetSize; |
+// using base::partitionAllocGetSize; |
+ |
const size_t kTestMaxAllocation = 4096; |
SizeSpecificPartitionAllocator<kTestMaxAllocation> allocator; |
PartitionAllocatorGeneric genericAllocator; |
const size_t kTestAllocSize = 16; |
-#if !ENABLE(ASSERT) |
+#if !DCHECK_IS_ON() |
const size_t kPointerOffset = 0; |
const size_t kExtraAllocSize = 0; |
#else |
-const size_t kPointerOffset = WTF::kCookieSize; |
-const size_t kExtraAllocSize = WTF::kCookieSize * 2; |
+const size_t kPointerOffset = kCookieSize; |
+const size_t kExtraAllocSize = kCookieSize * 2; |
#endif |
const size_t kRealAllocSize = kTestAllocSize + kExtraAllocSize; |
-const size_t kTestBucketIndex = kRealAllocSize >> WTF::kBucketShift; |
+const size_t kTestBucketIndex = kRealAllocSize >> kBucketShift; |
const char* typeName = nullptr; |
@@ -84,12 +72,12 @@ void TestShutdown() { |
EXPECT_TRUE(genericAllocator.shutdown()); |
} |
-#if !CPU(64BIT) || OS(POSIX) |
+#if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |
bool SetAddressSpaceLimit() { |
-#if !CPU(64BIT) |
+#if !defined(ARCH_CPU_64_BITS) |
// 32 bits => address space is limited already. |
return true; |
-#elif OS(POSIX) && !OS(MACOSX) |
+#elif defined(OS_POSIX) && !defined(OS_MACOSX) |
// Mac will accept RLIMIT_AS changes but it is not enforced. |
// See https://crbug.com/435269 and rdar://17576114. |
const size_t kAddressSpaceLimit = static_cast<size_t>(4096) * 1024 * 1024; |
@@ -108,9 +96,9 @@ bool SetAddressSpaceLimit() { |
} |
bool ClearAddressSpaceLimit() { |
-#if !CPU(64BIT) |
+#if !defined(ARCH_CPU_64_BITS) |
return true; |
-#elif OS(POSIX) |
+#elif defined(OS_POSIX) |
struct rlimit limit; |
if (getrlimit(RLIMIT_AS, &limit) != 0) |
return false; |
@@ -170,7 +158,7 @@ void CycleFreeCache(size_t size) { |
size_t realSize = size + kExtraAllocSize; |
size_t bucketIdx = realSize >> kBucketShift; |
PartitionBucket* bucket = &allocator.root()->buckets()[bucketIdx]; |
- ASSERT(!bucket->activePagesHead->numAllocatedSlots); |
+ DCHECK(!bucket->activePagesHead->numAllocatedSlots); |
for (size_t i = 0; i < kMaxFreeableSpans; ++i) { |
void* ptr = partitionAlloc(allocator.root(), size, typeName); |
@@ -195,7 +183,7 @@ void CycleGenericFreeCache(size_t size) { |
} |
void CheckPageInCore(void* ptr, bool inCore) { |
-#if OS(LINUX) |
+#if defined(OS_LINUX) |
unsigned char ret; |
EXPECT_EQ(0, mincore(ptr, kSystemPageSize, &ret)); |
EXPECT_EQ(inCore, ret); |
@@ -560,7 +548,7 @@ TEST(PartitionAllocTest, GenericAlloc) { |
// Check that the realloc copied correctly. |
char* newCharPtr = static_cast<char*>(newPtr); |
EXPECT_EQ(*newCharPtr, 'A'); |
-#if ENABLE(ASSERT) |
+#if DCHECK_IS_ON() |
// Subtle: this checks for an old bug where we copied too much from the |
// source of the realloc. The condition can be detected by a trashing of |
// the uninitialized value in the space of the upsized allocation. |
@@ -671,7 +659,7 @@ TEST(PartitionAllocTest, GenericAllocSizes) { |
EXPECT_EQ(ptr3, newPtr); |
newPtr = partitionAllocGeneric(genericAllocator.root(), size, typeName); |
EXPECT_EQ(ptr2, newPtr); |
-#if OS(LINUX) && !ENABLE(ASSERT) |
+#if defined(OS_LINUX) && !DCHECK_IS_ON() |
// On Linux, we have a guarantee that freelisting a page should cause its |
// contents to be nulled out. We check for null here to detect an bug we |
// had where a large slot size was causing us to not properly free all |
@@ -807,7 +795,7 @@ TEST(PartitionAllocTest, Realloc) { |
char* charPtr2 = static_cast<char*>(ptr2); |
EXPECT_EQ('A', charPtr2[0]); |
EXPECT_EQ('A', charPtr2[size - 1]); |
-#if ENABLE(ASSERT) |
+#if DCHECK_IS_ON() |
EXPECT_EQ(kUninitializedByte, static_cast<unsigned char>(charPtr2[size])); |
#endif |
@@ -819,7 +807,7 @@ TEST(PartitionAllocTest, Realloc) { |
char* charPtr = static_cast<char*>(ptr); |
EXPECT_EQ('A', charPtr[0]); |
EXPECT_EQ('A', charPtr[size - 2]); |
-#if ENABLE(ASSERT) |
+#if DCHECK_IS_ON() |
EXPECT_EQ(kUninitializedByte, static_cast<unsigned char>(charPtr[size - 1])); |
#endif |
@@ -1266,7 +1254,7 @@ TEST(PartitionAllocTest, LostFreePagesBug) { |
TestShutdown(); |
} |
-#if !CPU(64BIT) || OS(POSIX) |
+#if !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |
static void DoReturnNullTest(size_t allocSize) { |
TestSetup(); |
@@ -1319,7 +1307,7 @@ static void DoReturnNullTest(size_t allocSize) { |
// crash, and still returns null. The test tries to allocate 6 GB of memory in |
// 512 kB blocks. On 64-bit POSIX systems, the address space is limited to 4 GB |
// using setrlimit() first. |
-#if OS(MACOSX) |
+#if defined(OS_MACOSX) |
#define MAYBE_RepeatedReturnNull DISABLED_RepeatedReturnNull |
#else |
#define MAYBE_RepeatedReturnNull RepeatedReturnNull |
@@ -1330,7 +1318,7 @@ TEST(PartitionAllocTest, MAYBE_RepeatedReturnNull) { |
} |
// Another "return null" test but for larger, direct-mapped allocations. |
-#if OS(MACOSX) |
+#if defined(OS_MACOSX) |
#define MAYBE_RepeatedReturnNullDirect DISABLED_RepeatedReturnNullDirect |
#else |
#define MAYBE_RepeatedReturnNullDirect RepeatedReturnNullDirect |
@@ -1340,9 +1328,9 @@ TEST(PartitionAllocTest, MAYBE_RepeatedReturnNullDirect) { |
DoReturnNullTest(256 * 1024 * 1024); |
} |
-#endif // !CPU(64BIT) || OS(POSIX) |
+#endif // !defined(ARCH_CPU_64_BITS) || defined(OS_POSIX) |
-#if !OS(ANDROID) |
+#if !defined(OS_ANDROID) |
// Make sure that malloc(-1) dies. |
// In the past, we had an integer overflow that would alias malloc(-1) to |
@@ -1452,7 +1440,7 @@ TEST(PartitionAllocDeathTest, FreeWrongPartitionPage) { |
TestShutdown(); |
} |
-#endif // !OS(ANDROID) |
+#endif // !defined(OS_ANDROID) |
// Tests that partitionDumpStatsGeneric and partitionDumpStats runs without |
// crashing and returns non zero values when memory is allocated. |
@@ -2113,6 +2101,26 @@ TEST(PartitionAllocTest, PurgeDiscardable) { |
TestShutdown(); |
} |
-} // namespace WTF |
+TEST(PartitionAllocTest, CLZWorks) { |
+ EXPECT_EQ(32u, countLeadingZeros32(0u)); |
+ EXPECT_EQ(31u, countLeadingZeros32(1u)); |
+ EXPECT_EQ(1u, countLeadingZeros32(1u << 30)); |
+ EXPECT_EQ(0u, countLeadingZeros32(1u << 31)); |
+ |
+#if defined(ARCH_CPU_64_BITS) |
+ EXPECT_EQ(64u, countLeadingZerosSizet(0ull)); |
+ EXPECT_EQ(63u, countLeadingZerosSizet(1ull)); |
+ EXPECT_EQ(32u, countLeadingZerosSizet(1ull << 31)); |
+ EXPECT_EQ(1u, countLeadingZerosSizet(1ull << 62)); |
+ EXPECT_EQ(0u, countLeadingZerosSizet(1ull << 63)); |
+#else |
+ EXPECT_EQ(32u, countLeadingZerosSizet(0u)); |
+ EXPECT_EQ(31u, countLeadingZerosSizet(1u)); |
+ EXPECT_EQ(1u, countLeadingZerosSizet(1u << 30)); |
+ EXPECT_EQ(0u, countLeadingZerosSizet(1u << 31)); |
+#endif |
+} |
+ |
+} // namespace base |
#endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |