OLD | NEW |
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::getStats(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 |
242 class CountingVisitor : public Visitor { | 242 class CountingVisitor : public Visitor { |
243 public: | 243 public: |
244 CountingVisitor() | 244 CountingVisitor() |
245 : m_count(0) | 245 : m_count(0) |
246 { | 246 { |
247 } | 247 } |
248 | 248 |
249 virtual void mark(const void* object, TraceCallback) OVERRIDE | 249 virtual void mark(const void* object, TraceCallback) override |
250 { | 250 { |
251 if (object) | 251 if (object) |
252 m_count++; | 252 m_count++; |
253 } | 253 } |
254 | 254 |
255 virtual void mark(HeapObjectHeader* header, TraceCallback callback) OVERRIDE | 255 virtual void mark(HeapObjectHeader* header, TraceCallback callback) override |
256 { | 256 { |
257 ASSERT(header->payload()); | 257 ASSERT(header->payload()); |
258 m_count++; | 258 m_count++; |
259 } | 259 } |
260 | 260 |
261 virtual void mark(FinalizedHeapObjectHeader* header, TraceCallback callback)
OVERRIDE | 261 virtual void mark(FinalizedHeapObjectHeader* header, TraceCallback callback)
override |
262 { | 262 { |
263 ASSERT(header->payload()); | 263 ASSERT(header->payload()); |
264 m_count++; | 264 m_count++; |
265 } | 265 } |
266 | 266 |
267 virtual void registerDelayedMarkNoTracing(const void*) OVERRIDE { } | 267 virtual void registerDelayedMarkNoTracing(const void*) override { } |
268 virtual void registerWeakMembers(const void*, const void*, WeakPointerCallba
ck) OVERRIDE { } | 268 virtual void registerWeakMembers(const void*, const void*, WeakPointerCallba
ck) override { } |
269 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall
back) OVERRIDE { } | 269 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall
back) override { } |
270 #if ENABLE(ASSERT) | 270 #if ENABLE(ASSERT) |
271 virtual bool weakTableRegistered(const void*) OVERRIDE { return false; } | 271 virtual bool weakTableRegistered(const void*) override { return false; } |
272 #endif | 272 #endif |
273 virtual void registerWeakCell(void**, WeakPointerCallback) OVERRIDE { } | 273 virtual void registerWeakCell(void**, WeakPointerCallback) override { } |
274 virtual bool isMarked(const void*) OVERRIDE { return false; } | 274 virtual bool isMarked(const void*) override { return false; } |
275 | 275 |
276 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) | 276 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) |
277 | 277 |
278 size_t count() { return m_count; } | 278 size_t count() { return m_count; } |
279 void reset() { m_count = 0; } | 279 void reset() { m_count = 0; } |
280 | 280 |
281 private: | 281 private: |
282 size_t m_count; | 282 size_t m_count; |
283 }; | 283 }; |
284 | 284 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 }; | 459 }; |
460 | 460 |
461 class ThreadedHeapTester : public ThreadedTesterBase { | 461 class ThreadedHeapTester : public ThreadedTesterBase { |
462 public: | 462 public: |
463 static void test() | 463 static void test() |
464 { | 464 { |
465 ThreadedTesterBase::test(new ThreadedHeapTester); | 465 ThreadedTesterBase::test(new ThreadedHeapTester); |
466 } | 466 } |
467 | 467 |
468 protected: | 468 protected: |
469 virtual void runThread() OVERRIDE | 469 virtual void runThread() override |
470 { | 470 { |
471 ThreadState::attach(); | 471 ThreadState::attach(); |
472 | 472 |
473 int gcCount = 0; | 473 int gcCount = 0; |
474 while (!done()) { | 474 while (!done()) { |
475 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); | 475 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); |
476 { | 476 { |
477 Persistent<IntWrapper> wrapper; | 477 Persistent<IntWrapper> wrapper; |
478 | 478 |
479 typedef Persistent<IntWrapper, GlobalPersistents> GlobalIntWrapp
erPersistent; | 479 typedef Persistent<IntWrapper, GlobalPersistents> GlobalIntWrapp
erPersistent; |
(...skipping 27 matching lines...) Expand all Loading... |
507 }; | 507 }; |
508 | 508 |
509 class ThreadedWeaknessTester : public ThreadedTesterBase { | 509 class ThreadedWeaknessTester : public ThreadedTesterBase { |
510 public: | 510 public: |
511 static void test() | 511 static void test() |
512 { | 512 { |
513 ThreadedTesterBase::test(new ThreadedWeaknessTester); | 513 ThreadedTesterBase::test(new ThreadedWeaknessTester); |
514 } | 514 } |
515 | 515 |
516 private: | 516 private: |
517 virtual void runThread() OVERRIDE | 517 virtual void runThread() override |
518 { | 518 { |
519 ThreadState::attach(); | 519 ThreadState::attach(); |
520 | 520 |
521 int gcCount = 0; | 521 int gcCount = 0; |
522 while (!done()) { | 522 while (!done()) { |
523 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); | 523 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); |
524 { | 524 { |
525 Persistent<HeapHashMap<ThreadMarker, WeakMember<IntWrapper> > >
weakMap = new HeapHashMap<ThreadMarker, WeakMember<IntWrapper> >; | 525 Persistent<HeapHashMap<ThreadMarker, WeakMember<IntWrapper> > >
weakMap = new HeapHashMap<ThreadMarker, WeakMember<IntWrapper> >; |
526 PersistentHeapHashMap<ThreadMarker, WeakMember<IntWrapper> > wea
kMap2; | 526 PersistentHeapHashMap<ThreadMarker, WeakMember<IntWrapper> > wea
kMap2; |
527 | 527 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 static Foo* create(Bar* bar) | 711 static Foo* create(Bar* bar) |
712 { | 712 { |
713 return new Foo(bar); | 713 return new Foo(bar); |
714 } | 714 } |
715 | 715 |
716 static Foo* create(Foo* foo) | 716 static Foo* create(Foo* foo) |
717 { | 717 { |
718 return new Foo(foo); | 718 return new Foo(foo); |
719 } | 719 } |
720 | 720 |
721 virtual void trace(Visitor* visitor) OVERRIDE | 721 virtual void trace(Visitor* visitor) override |
722 { | 722 { |
723 if (m_pointsToFoo) | 723 if (m_pointsToFoo) |
724 visitor->mark(static_cast<Foo*>(m_bar)); | 724 visitor->mark(static_cast<Foo*>(m_bar)); |
725 else | 725 else |
726 visitor->mark(m_bar); | 726 visitor->mark(m_bar); |
727 } | 727 } |
728 | 728 |
729 private: | 729 private: |
730 Foo(Bar* bar) | 730 Foo(Bar* bar) |
731 : Bar() | 731 : Bar() |
(...skipping 13 matching lines...) Expand all Loading... |
745 bool m_pointsToFoo; | 745 bool m_pointsToFoo; |
746 }; | 746 }; |
747 | 747 |
748 class Bars : public Bar { | 748 class Bars : public Bar { |
749 public: | 749 public: |
750 static Bars* create() | 750 static Bars* create() |
751 { | 751 { |
752 return new Bars(); | 752 return new Bars(); |
753 } | 753 } |
754 | 754 |
755 virtual void trace(Visitor* visitor) OVERRIDE | 755 virtual void trace(Visitor* visitor) override |
756 { | 756 { |
757 for (unsigned i = 0; i < m_width; i++) | 757 for (unsigned i = 0; i < m_width; i++) |
758 visitor->trace(m_bars[i]); | 758 visitor->trace(m_bars[i]); |
759 } | 759 } |
760 | 760 |
761 unsigned getWidth() const | 761 unsigned getWidth() const |
762 { | 762 { |
763 return m_width; | 763 return m_width; |
764 } | 764 } |
765 | 765 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 867 |
868 private: | 868 private: |
869 RefCountedAndGarbageCollected2() | 869 RefCountedAndGarbageCollected2() |
870 { | 870 { |
871 } | 871 } |
872 }; | 872 }; |
873 | 873 |
874 int RefCountedAndGarbageCollected2::s_destructorCalls = 0; | 874 int RefCountedAndGarbageCollected2::s_destructorCalls = 0; |
875 | 875 |
876 #define DEFINE_VISITOR_METHODS(Type) \ | 876 #define DEFINE_VISITOR_METHODS(Type) \ |
877 virtual void mark(const Type* object, TraceCallback callback) OVERRIDE \ | 877 virtual void mark(const Type* object, TraceCallback callback) override \ |
878 { \ | 878 { \ |
879 mark(object); \ | 879 mark(object); \ |
880 } \ | 880 } \ |
881 | 881 |
882 class RefCountedGarbageCollectedVisitor : public CountingVisitor { | 882 class RefCountedGarbageCollectedVisitor : public CountingVisitor { |
883 public: | 883 public: |
884 RefCountedGarbageCollectedVisitor(int expected, void** objects) | 884 RefCountedGarbageCollectedVisitor(int expected, void** objects) |
885 : m_count(0) | 885 : m_count(0) |
886 , m_expectedCount(expected) | 886 , m_expectedCount(expected) |
887 , m_expectedObjects(objects) | 887 , m_expectedObjects(objects) |
888 { | 888 { |
889 } | 889 } |
890 | 890 |
891 void mark(const void* ptr) { markNoTrace(ptr); } | 891 void mark(const void* ptr) { markNoTrace(ptr); } |
892 | 892 |
893 virtual void markNoTrace(const void* ptr) | 893 virtual void markNoTrace(const void* ptr) |
894 { | 894 { |
895 if (!ptr) | 895 if (!ptr) |
896 return; | 896 return; |
897 if (m_count < m_expectedCount) | 897 if (m_count < m_expectedCount) |
898 EXPECT_TRUE(expectedObject(ptr)); | 898 EXPECT_TRUE(expectedObject(ptr)); |
899 else | 899 else |
900 EXPECT_FALSE(expectedObject(ptr)); | 900 EXPECT_FALSE(expectedObject(ptr)); |
901 m_count++; | 901 m_count++; |
902 } | 902 } |
903 | 903 |
904 virtual void mark(const void* ptr, TraceCallback) OVERRIDE | 904 virtual void mark(const void* ptr, TraceCallback) override |
905 { | 905 { |
906 mark(ptr); | 906 mark(ptr); |
907 } | 907 } |
908 | 908 |
909 virtual void mark(HeapObjectHeader* header, TraceCallback callback) OVERRIDE | 909 virtual void mark(HeapObjectHeader* header, TraceCallback callback) override |
910 { | 910 { |
911 mark(header->payload()); | 911 mark(header->payload()); |
912 } | 912 } |
913 | 913 |
914 virtual void mark(FinalizedHeapObjectHeader* header, TraceCallback callback)
OVERRIDE | 914 virtual void mark(FinalizedHeapObjectHeader* header, TraceCallback callback)
override |
915 { | 915 { |
916 mark(header->payload()); | 916 mark(header->payload()); |
917 } | 917 } |
918 | 918 |
919 bool validate() { return m_count >= m_expectedCount; } | 919 bool validate() { return m_count >= m_expectedCount; } |
920 void reset() { m_count = 0; } | 920 void reset() { m_count = 0; } |
921 | 921 |
922 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) | 922 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) |
923 | 923 |
924 private: | 924 private: |
(...skipping 13 matching lines...) Expand all Loading... |
938 | 938 |
939 #undef DEFINE_VISITOR_METHODS | 939 #undef DEFINE_VISITOR_METHODS |
940 | 940 |
941 class Weak : public Bar { | 941 class Weak : public Bar { |
942 public: | 942 public: |
943 static Weak* create(Bar* strong, Bar* weak) | 943 static Weak* create(Bar* strong, Bar* weak) |
944 { | 944 { |
945 return new Weak(strong, weak); | 945 return new Weak(strong, weak); |
946 } | 946 } |
947 | 947 |
948 virtual void trace(Visitor* visitor) OVERRIDE | 948 virtual void trace(Visitor* visitor) override |
949 { | 949 { |
950 visitor->trace(m_strongBar); | 950 visitor->trace(m_strongBar); |
951 visitor->registerWeakMembers(this, zapWeakMembers); | 951 visitor->registerWeakMembers(this, zapWeakMembers); |
952 } | 952 } |
953 | 953 |
954 static void zapWeakMembers(Visitor* visitor, void* self) | 954 static void zapWeakMembers(Visitor* visitor, void* self) |
955 { | 955 { |
956 reinterpret_cast<Weak*>(self)->zapWeakMembers(visitor); | 956 reinterpret_cast<Weak*>(self)->zapWeakMembers(visitor); |
957 } | 957 } |
958 | 958 |
(...skipping 18 matching lines...) Expand all Loading... |
977 Bar* m_weakBar; | 977 Bar* m_weakBar; |
978 }; | 978 }; |
979 | 979 |
980 class WithWeakMember : public Bar { | 980 class WithWeakMember : public Bar { |
981 public: | 981 public: |
982 static WithWeakMember* create(Bar* strong, Bar* weak) | 982 static WithWeakMember* create(Bar* strong, Bar* weak) |
983 { | 983 { |
984 return new WithWeakMember(strong, weak); | 984 return new WithWeakMember(strong, weak); |
985 } | 985 } |
986 | 986 |
987 virtual void trace(Visitor* visitor) OVERRIDE | 987 virtual void trace(Visitor* visitor) override |
988 { | 988 { |
989 visitor->trace(m_strongBar); | 989 visitor->trace(m_strongBar); |
990 visitor->trace(m_weakBar); | 990 visitor->trace(m_weakBar); |
991 } | 991 } |
992 | 992 |
993 bool strongIsThere() { return !!m_strongBar; } | 993 bool strongIsThere() { return !!m_strongBar; } |
994 bool weakIsThere() { return !!m_weakBar; } | 994 bool weakIsThere() { return !!m_weakBar; } |
995 | 995 |
996 private: | 996 private: |
997 WithWeakMember(Bar* strongBar, Bar* weakBar) | 997 WithWeakMember(Bar* strongBar, Bar* weakBar) |
(...skipping 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5395 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) | 5395 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) |
5396 { | 5396 { |
5397 new NonNodeAllocatingNodeInDestructor(); | 5397 new NonNodeAllocatingNodeInDestructor(); |
5398 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 5398 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
5399 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); | 5399 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); |
5400 delete NonNodeAllocatingNodeInDestructor::s_node; | 5400 delete NonNodeAllocatingNodeInDestructor::s_node; |
5401 NonNodeAllocatingNodeInDestructor::s_node = 0; | 5401 NonNodeAllocatingNodeInDestructor::s_node = 0; |
5402 } | 5402 } |
5403 | 5403 |
5404 } // namespace blink | 5404 } // namespace blink |
OLD | NEW |