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 2222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2233 clearOutOldGarbage(&initialHeapStats); | 2233 clearOutOldGarbage(&initialHeapStats); |
2234 IntWrapper::s_destructorCalls = 0; | 2234 IntWrapper::s_destructorCalls = 0; |
2235 Persistent<OffHeapContainer> container = OffHeapContainer::create(); | 2235 Persistent<OffHeapContainer> container = OffHeapContainer::create(); |
2236 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 2236 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
2237 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 2237 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
2238 container = 0; | 2238 container = 0; |
2239 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 2239 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
2240 EXPECT_EQ(7, IntWrapper::s_destructorCalls); | 2240 EXPECT_EQ(7, IntWrapper::s_destructorCalls); |
2241 } | 2241 } |
2242 | 2242 |
| 2243 TEST(HeapTest, PersistentHeapCollectionTypes) |
| 2244 { |
| 2245 HeapStats initialHeapSize; |
| 2246 IntWrapper::s_destructorCalls = 0; |
| 2247 |
| 2248 typedef HeapVector<Member<IntWrapper> > Vec; |
| 2249 typedef PersistentHeapVector<Member<IntWrapper> > PVec; |
| 2250 typedef PersistentHeapHashSet<Member<IntWrapper> > PSet; |
| 2251 typedef PersistentHeapHashMap<Member<IntWrapper>, Member<IntWrapper> > PMap; |
| 2252 |
| 2253 clearOutOldGarbage(&initialHeapSize); |
| 2254 { |
| 2255 PVec* pVec = new PVec(); |
| 2256 PSet* pSet = new PSet(); |
| 2257 PMap* pMap = new PMap(); |
| 2258 |
| 2259 IntWrapper* one(IntWrapper::create(1)); |
| 2260 IntWrapper* two(IntWrapper::create(2)); |
| 2261 IntWrapper* three(IntWrapper::create(3)); |
| 2262 IntWrapper* four(IntWrapper::create(4)); |
| 2263 IntWrapper* five(IntWrapper::create(5)); |
| 2264 IntWrapper* six(IntWrapper::create(6)); |
| 2265 |
| 2266 pVec->append(one); |
| 2267 pVec->append(two); |
| 2268 |
| 2269 Vec* vec = new Vec(); |
| 2270 vec->swap(*pVec); |
| 2271 |
| 2272 pVec->append(two); |
| 2273 pVec->append(three); |
| 2274 |
| 2275 pSet->add(four); |
| 2276 pMap->add(five, six); |
| 2277 |
| 2278 // Collect |map| and |two|. |
| 2279 vec = 0; |
| 2280 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 2281 EXPECT_EQ(1, IntWrapper::s_destructorCalls); |
| 2282 |
| 2283 EXPECT_EQ(2u, pVec->size()); |
| 2284 EXPECT_TRUE(pVec->at(0) == two); |
| 2285 EXPECT_TRUE(pVec->at(1) == three); |
| 2286 |
| 2287 EXPECT_EQ(1u, pSet->size()); |
| 2288 EXPECT_TRUE(pSet->contains(four)); |
| 2289 |
| 2290 EXPECT_EQ(1u, pMap->size()); |
| 2291 EXPECT_TRUE(pMap->get(five) == six); |
| 2292 |
| 2293 delete pVec; |
| 2294 delete pSet; |
| 2295 delete pMap; |
| 2296 } |
| 2297 |
| 2298 // Collect previous roots. |
| 2299 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 2300 EXPECT_EQ(6, IntWrapper::s_destructorCalls); |
| 2301 } |
| 2302 |
2243 DEFINE_GC_INFO(Bar); | 2303 DEFINE_GC_INFO(Bar); |
2244 DEFINE_GC_INFO(Baz); | 2304 DEFINE_GC_INFO(Baz); |
2245 DEFINE_GC_INFO(ClassWithMember); | 2305 DEFINE_GC_INFO(ClassWithMember); |
2246 DEFINE_GC_INFO(ConstructorAllocation); | 2306 DEFINE_GC_INFO(ConstructorAllocation); |
2247 DEFINE_GC_INFO(Container); | 2307 DEFINE_GC_INFO(Container); |
2248 DEFINE_GC_INFO(HeapAllocatedArray); | 2308 DEFINE_GC_INFO(HeapAllocatedArray); |
2249 DEFINE_GC_INFO(HeapTestSuperClass); | 2309 DEFINE_GC_INFO(HeapTestSuperClass); |
2250 DEFINE_GC_INFO(IntWrapper); | 2310 DEFINE_GC_INFO(IntWrapper); |
2251 DEFINE_GC_INFO(LargeObject); | 2311 DEFINE_GC_INFO(LargeObject); |
2252 DEFINE_GC_INFO(OffHeapContainer); | 2312 DEFINE_GC_INFO(OffHeapContainer); |
2253 DEFINE_GC_INFO(PointsBack); | 2313 DEFINE_GC_INFO(PointsBack); |
2254 DEFINE_GC_INFO(RefCountedAndGarbageCollected); | 2314 DEFINE_GC_INFO(RefCountedAndGarbageCollected); |
2255 DEFINE_GC_INFO(RefCountedAndGarbageCollected2); | 2315 DEFINE_GC_INFO(RefCountedAndGarbageCollected2); |
2256 DEFINE_GC_INFO(SimpleFinalizedObject); | 2316 DEFINE_GC_INFO(SimpleFinalizedObject); |
2257 DEFINE_GC_INFO(SimpleObject); | 2317 DEFINE_GC_INFO(SimpleObject); |
2258 DEFINE_GC_INFO(SuperClass); | 2318 DEFINE_GC_INFO(SuperClass); |
2259 DEFINE_GC_INFO(SubData); | 2319 DEFINE_GC_INFO(SubData); |
2260 DEFINE_GC_INFO(TestTypedHeapClass); | 2320 DEFINE_GC_INFO(TestTypedHeapClass); |
2261 DEFINE_GC_INFO(TraceCounter); | 2321 DEFINE_GC_INFO(TraceCounter); |
2262 DEFINE_GC_INFO(TransitionRefCounted); | 2322 DEFINE_GC_INFO(TransitionRefCounted); |
2263 | 2323 |
2264 } // namespace | 2324 } // namespace |
OLD | NEW |