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

Side by Side Diff: Source/platform/heap/HeapTest.cpp

Issue 634243004: Oilpan: Simplify Heap::allocate (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 private: 221 private:
222 ThreadState* m_state; 222 ThreadState* m_state;
223 ThreadState::SafePointScope m_safePointScope; 223 ThreadState::SafePointScope m_safePointScope;
224 bool m_parkedAllThreads; // False if we fail to park all threads 224 bool m_parkedAllThreads; // False if we fail to park all threads
225 }; 225 };
226 226
227 static void getHeapStats(HeapStats* stats) 227 static void getHeapStats(HeapStats* stats)
228 { 228 {
229 TestGCScope scope(ThreadState::NoHeapPointersOnStack); 229 TestGCScope scope(ThreadState::NoHeapPointersOnStack);
230 EXPECT_TRUE(scope.allThreadsParked()); 230 EXPECT_TRUE(scope.allThreadsParked());
231 Heap::getStats(stats); 231 Heap::getStatsForTesting(stats);
232 } 232 }
233 233
234 #define DEFINE_VISITOR_METHODS(Type) \ 234 #define DEFINE_VISITOR_METHODS(Type) \
235 virtual void mark(const Type* object, TraceCallback callback) override \ 235 virtual void mark(const Type* object, TraceCallback callback) override \
236 { \ 236 { \
237 if (object) \ 237 if (object) \
238 m_count++; \ 238 m_count++; \
239 } \ 239 } \
240 virtual bool isMarked(const Type*) override { return false; } 240 virtual bool isMarked(const Type*) override { return false; }
241 241
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 if (testPagesAllocated) 1595 if (testPagesAllocated)
1596 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1) ); 1596 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1) );
1597 } 1597 }
1598 1598
1599 clearOutOldGarbage(&heapStats); 1599 clearOutOldGarbage(&heapStats);
1600 total -= 96; 1600 total -= 96;
1601 slack -= 8; 1601 slack -= 8;
1602 if (testPagesAllocated) 1602 if (testPagesAllocated)
1603 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)); 1603 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1));
1604 1604
1605 DynamicallySizedObject* bigAreaRaw = bigArea;
1606 // Clear the persistent, so that the big area will be garbage collected. 1605 // Clear the persistent, so that the big area will be garbage collected.
1607 bigArea.release(); 1606 bigArea.release();
1608 clearOutOldGarbage(&heapStats); 1607 clearOutOldGarbage(&heapStats);
1609 1608
1610 total -= big; 1609 total -= big;
1611 slack -= 4; 1610 slack -= 4;
1612 getHeapStats(&heapStats); 1611 getHeapStats(&heapStats);
1613 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack); 1612 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack);
1614 if (testPagesAllocated) 1613 if (testPagesAllocated)
1615 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)); 1614 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1));
1616 1615
1617 // Endless loop unless we eventually get the memory back that we just freed.
haraken 2014/10/23 04:20:50 Removed this test because the test result depends
1618 while (true) {
1619 Persistent<DynamicallySizedObject>* alloc = new Persistent<DynamicallySi zedObject>(DynamicallySizedObject::create(big / 2));
1620 slack += 4;
1621 persistents[persistentCount++] = alloc;
1622 EXPECT_LT(persistentCount, numPersistents);
1623 total += big / 2;
1624 if (bigAreaRaw == alloc->get())
1625 break;
1626 }
1627
1628 getHeapStats(&heapStats); 1616 getHeapStats(&heapStats);
1629 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack); 1617 CheckWithSlack(baseLevel + total, heapStats.totalObjectSpace(), slack);
1630 if (testPagesAllocated) 1618 if (testPagesAllocated)
1631 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1)); 1619 EXPECT_EQ(0ul, heapStats.totalAllocatedSpace() & (blinkPageSize - 1));
1632 1620
1633 for (size_t i = 0; i < persistentCount; i++) { 1621 for (size_t i = 0; i < persistentCount; i++) {
1634 delete persistents[i]; 1622 delete persistents[i];
1635 persistents[i] = 0; 1623 persistents[i] = 0;
1636 } 1624 }
1637 1625
(...skipping 3759 matching lines...) Expand 10 before | Expand all | Expand 10 after
5397 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) 5385 TEST(HeapTest, NonNodeAllocatingNodeInDestructor)
5398 { 5386 {
5399 new NonNodeAllocatingNodeInDestructor(); 5387 new NonNodeAllocatingNodeInDestructor();
5400 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 5388 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
5401 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); 5389 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value());
5402 delete NonNodeAllocatingNodeInDestructor::s_node; 5390 delete NonNodeAllocatingNodeInDestructor::s_node;
5403 NonNodeAllocatingNodeInDestructor::s_node = 0; 5391 NonNodeAllocatingNodeInDestructor::s_node = 0;
5404 } 5392 }
5405 5393
5406 } // namespace blink 5394 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698