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

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

Issue 222653003: Oilpan: Fix isAlive dispatching for GarbageCollectedMixins. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add comment to virtual method Created 6 years, 8 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
« no previous file with comments | « no previous file | Source/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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 private: 169 private:
170 size_t m_count; 170 size_t m_count;
171 }; 171 };
172 172
173 class SimpleObject : public GarbageCollected<SimpleObject> { 173 class SimpleObject : public GarbageCollected<SimpleObject> {
174 public: 174 public:
175 static SimpleObject* create() { return new SimpleObject(); } 175 static SimpleObject* create() { return new SimpleObject(); }
176 void trace(Visitor*) { } 176 void trace(Visitor*) { }
177 char getPayload(int i) { return payload[i]; } 177 char getPayload(int i) { return payload[i]; }
178 // This virtual method is unused but it is here to make sure
179 // that this object has a vtable. This object is used
180 // as the super class for objects that also have garbage
181 // collected mixins and having a virtual here makes sure
182 // that adjustment is needed both for marking and for isAlive
183 // checks.
184 virtual void virtualMethod() { }
178 protected: 185 protected:
179 SimpleObject() { } 186 SimpleObject() { }
180 char payload[64]; 187 char payload[64];
181 }; 188 };
182 189
183 #undef DEFINE_VISITOR_METHODS 190 #undef DEFINE_VISITOR_METHODS
184 191
185 class HeapTestSuperClass : public GarbageCollectedFinalized<HeapTestSuperClass> { 192 class HeapTestSuperClass : public GarbageCollectedFinalized<HeapTestSuperClass> {
186 public: 193 public:
187 static HeapTestSuperClass* create() 194 static HeapTestSuperClass* create()
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 ++s_aliveCount; 1137 ++s_aliveCount;
1131 } 1138 }
1132 }; 1139 };
1133 1140
1134 int TransitionRefCounted::s_aliveCount = 0; 1141 int TransitionRefCounted::s_aliveCount = 0;
1135 1142
1136 class Mixin : public GarbageCollectedMixin { 1143 class Mixin : public GarbageCollectedMixin {
1137 public: 1144 public:
1138 virtual void trace(Visitor* visitor) { } 1145 virtual void trace(Visitor* visitor) { }
1139 1146
1140 char getPayload(int i) { return m_padding[i]; } 1147 virtual char getPayload(int i) { return m_padding[i]; }
1141 1148
1142 protected: 1149 protected:
1143 // This is to force ptr diff for SimpleObject, Mixin, and UseMixin.
1144 int m_padding[8]; 1150 int m_padding[8];
1145 }; 1151 };
1146 1152
1147 class UseMixin : public SimpleObject, public Mixin { 1153 class UseMixin : public SimpleObject, public Mixin {
1148 USING_GARBAGE_COLLECTED_MIXIN(UseMixin) 1154 USING_GARBAGE_COLLECTED_MIXIN(UseMixin)
1149 public: 1155 public:
1150 static UseMixin* create() 1156 static UseMixin* create()
1151 { 1157 {
1152 return new UseMixin(); 1158 return new UseMixin();
1153 } 1159 }
(...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after
2976 Persistent<HeapHashMap<void*, IntVector> > keepAlive(map); 2982 Persistent<HeapHashMap<void*, IntVector> > keepAlive(map);
2977 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 2983 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
2978 EXPECT_EQ(1u, map->get(key).size()); 2984 EXPECT_EQ(1u, map->get(key).size());
2979 EXPECT_EQ(0, IntWrapper::s_destructorCalls); 2985 EXPECT_EQ(0, IntWrapper::s_destructorCalls);
2980 2986
2981 keepAlive = nullptr; 2987 keepAlive = nullptr;
2982 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 2988 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
2983 EXPECT_EQ(1, IntWrapper::s_destructorCalls); 2989 EXPECT_EQ(1, IntWrapper::s_destructorCalls);
2984 } 2990 }
2985 2991
2986 TEST(heap, GarbageCollectedMixin) 2992 TEST(HeapTest, GarbageCollectedMixin)
2987 { 2993 {
2988 HeapStats initialHeapStats; 2994 HeapStats initialHeapStats;
2989 clearOutOldGarbage(&initialHeapStats); 2995 clearOutOldGarbage(&initialHeapStats);
2990 2996
2991 Persistent<UseMixin> usemixin = UseMixin::create(); 2997 Persistent<UseMixin> usemixin = UseMixin::create();
2992 ASSERT_EQ(0, UseMixin::s_traceCount); 2998 EXPECT_EQ(0, UseMixin::s_traceCount);
2993 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 2999 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
2994 ASSERT_EQ(1, UseMixin::s_traceCount); 3000 EXPECT_EQ(1, UseMixin::s_traceCount);
2995 3001
2996 Persistent<Mixin> mixin = usemixin; 3002 Persistent<Mixin> mixin = usemixin;
2997 usemixin = nullptr; 3003 usemixin = nullptr;
2998 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 3004 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
2999 ASSERT_EQ(2, UseMixin::s_traceCount); 3005 EXPECT_EQ(2, UseMixin::s_traceCount);
3006
3007 PersistentHeapHashSet<WeakMember<Mixin> > weakMap;
3008 weakMap.add(UseMixin::create());
3009 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
3010 EXPECT_EQ(0u, weakMap.size());
3000 } 3011 }
3001 3012
3002 TEST(HeapTest, CollectionNesting2) 3013 TEST(HeapTest, CollectionNesting2)
3003 { 3014 {
3004 HeapStats initialStats; 3015 HeapStats initialStats;
3005 clearOutOldGarbage(&initialStats); 3016 clearOutOldGarbage(&initialStats);
3006 void* key = &IntWrapper::s_destructorCalls; 3017 void* key = &IntWrapper::s_destructorCalls;
3007 IntWrapper::s_destructorCalls = 0; 3018 IntWrapper::s_destructorCalls = 0;
3008 typedef HeapHashSet<Member<IntWrapper> > IntSet; 3019 typedef HeapHashSet<Member<IntWrapper> > IntSet;
3009 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>(); 3020 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>();
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
3216 { 3227 {
3217 HeapHashMap<SimpleClassWithDestructor*, OwnPtr<SimpleClassWithDestructor> > map; 3228 HeapHashMap<SimpleClassWithDestructor*, OwnPtr<SimpleClassWithDestructor> > map;
3218 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); 3229 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor();
3219 map.add(hasDestructor, adoptPtr(hasDestructor)); 3230 map.add(hasDestructor, adoptPtr(hasDestructor));
3220 SimpleClassWithDestructor::s_wasDestructed = false; 3231 SimpleClassWithDestructor::s_wasDestructed = false;
3221 map.clear(); 3232 map.clear();
3222 ASSERT(SimpleClassWithDestructor::s_wasDestructed); 3233 ASSERT(SimpleClassWithDestructor::s_wasDestructed);
3223 } 3234 }
3224 3235
3225 } // WebCore namespace 3236 } // WebCore namespace
OLDNEW
« no previous file with comments | « no previous file | Source/heap/Visitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698