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

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

Issue 807003004: Templatize visitor arguments for TraceTrait mark and trace methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 5 years, 12 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
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/platform/heap/Visitor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 { 51 {
52 return new IntWrapper(x); 52 return new IntWrapper(x);
53 } 53 }
54 54
55 virtual ~IntWrapper() 55 virtual ~IntWrapper()
56 { 56 {
57 ++s_destructorCalls; 57 ++s_destructorCalls;
58 } 58 }
59 59
60 static int s_destructorCalls; 60 static int s_destructorCalls;
61 static void trace(Visitor*) { } 61 void trace(Visitor*) { }
62 62
63 int value() const { return m_x; } 63 int value() const { return m_x; }
64 64
65 bool operator==(const IntWrapper& other) const { return other.value() == val ue(); } 65 bool operator==(const IntWrapper& other) const { return other.value() == val ue(); }
66 66
67 unsigned hash() { return IntHash<int>::hash(m_x); } 67 unsigned hash() { return IntHash<int>::hash(m_x); }
68 68
69 IntWrapper(int x) : m_x(x) { } 69 IntWrapper(int x) : m_x(x) { }
70 70
71 private: 71 private:
72 IntWrapper(); 72 IntWrapper();
73 int m_x; 73 int m_x;
74 }; 74 };
75 static_assert(WTF::NeedsTracing<IntWrapper>::value, "NeedsTracing macro failed t o recognize trace method.");
75 76
76 class ThreadMarker { 77 class ThreadMarker {
77 public: 78 public:
78 ThreadMarker() : m_creatingThread(reinterpret_cast<ThreadState*>(0)), m_num( 0) { } 79 ThreadMarker() : m_creatingThread(reinterpret_cast<ThreadState*>(0)), m_num( 0) { }
79 ThreadMarker(unsigned i) : m_creatingThread(ThreadState::current()), m_num(i ) { } 80 ThreadMarker(unsigned i) : m_creatingThread(ThreadState::current()), m_num(i ) { }
80 ThreadMarker(WTF::HashTableDeletedValueType deleted) : m_creatingThread(rein terpret_cast<ThreadState*>(-1)), m_num(0) { } 81 ThreadMarker(WTF::HashTableDeletedValueType deleted) : m_creatingThread(rein terpret_cast<ThreadState*>(-1)), m_num(0) { }
81 ~ThreadMarker() 82 ~ThreadMarker()
82 { 83 {
83 EXPECT_TRUE((m_creatingThread == ThreadState::current()) 84 EXPECT_TRUE((m_creatingThread == ThreadState::current())
84 || (m_creatingThread == reinterpret_cast<ThreadState*>(0)) 85 || (m_creatingThread == reinterpret_cast<ThreadState*>(0))
(...skipping 3457 matching lines...) Expand 10 before | Expand all | Expand 10 after
3542 3543
3543 TEST(HeapTest, CollectionNesting) 3544 TEST(HeapTest, CollectionNesting)
3544 { 3545 {
3545 clearOutOldGarbage(); 3546 clearOutOldGarbage();
3546 int* key = &IntWrapper::s_destructorCalls; 3547 int* key = &IntWrapper::s_destructorCalls;
3547 IntWrapper::s_destructorCalls = 0; 3548 IntWrapper::s_destructorCalls = 0;
3548 typedef HeapVector<Member<IntWrapper> > IntVector; 3549 typedef HeapVector<Member<IntWrapper> > IntVector;
3549 typedef HeapDeque<Member<IntWrapper> > IntDeque; 3550 typedef HeapDeque<Member<IntWrapper> > IntDeque;
3550 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); 3551 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>();
3551 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); 3552 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>();
3553 static_assert(WTF::NeedsTracing<IntVector>::value, "Failed to recognize Heap Vector as NeedsTracing");
3554 static_assert(WTF::NeedsTracing<IntDeque>::value, "Failed to recognize HeapD eque as NeedsTracing");
3552 3555
3553 map->add(key, IntVector()); 3556 map->add(key, IntVector());
3554 map2->add(key, IntDeque()); 3557 map2->add(key, IntDeque());
3555 3558
3556 HeapHashMap<void*, IntVector>::iterator it = map->find(key); 3559 HeapHashMap<void*, IntVector>::iterator it = map->find(key);
3557 EXPECT_EQ(0u, map->get(key).size()); 3560 EXPECT_EQ(0u, map->get(key).size());
3558 3561
3559 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key); 3562 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key);
3560 EXPECT_EQ(0u, map2->get(key).size()); 3563 EXPECT_EQ(0u, map2->get(key).size());
3561 3564
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after
5341 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 5344 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
5342 5345
5343 // Verify that the DeepEagerly chain isn't completely unravelled 5346 // Verify that the DeepEagerly chain isn't completely unravelled
5344 // by performing eager trace() calls, but the explicit mark 5347 // by performing eager trace() calls, but the explicit mark
5345 // stack is switched once some nesting limit is exceeded. 5348 // stack is switched once some nesting limit is exceeded.
5346 EXPECT_GT(DeepEagerly::sTraceLazy, 2); 5349 EXPECT_GT(DeepEagerly::sTraceLazy, 2);
5347 #endif 5350 #endif
5348 } 5351 }
5349 5352
5350 } // namespace blink 5353 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/platform/heap/Visitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698