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

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

Issue 2815663002: Disable collection backing reallocation during pre finalizer (Closed)
Patch Set: fix Created 3 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
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 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 for (int i = 0; i < 32; ++i) 1492 for (int i = 0; i < 32; ++i)
1493 LargeHeapObject::Create(); 1493 LargeHeapObject::Create();
1494 } 1494 }
1495 1495
1496 DEFINE_INLINE_TRACE() {} 1496 DEFINE_INLINE_TRACE() {}
1497 1497
1498 private: 1498 private:
1499 Persistent<IntWrapper>* wrapper_; 1499 Persistent<IntWrapper>* wrapper_;
1500 }; 1500 };
1501 1501
1502 class PreFinalizerBackingReallocationForbiddenCheck
1503 : public GarbageCollectedFinalized<
1504 PreFinalizerBackingReallocationForbiddenCheck> {
1505 USING_PRE_FINALIZER(PreFinalizerBackingReallocationForbiddenCheck, Dispose);
1506
1507 public:
1508 PreFinalizerBackingReallocationForbiddenCheck() {
1509 vector_.push_back(nullptr);
1510 EXPECT_LT(0ul, vector_.Capacity());
1511 for (int i = 1; i <= 32; ++i) {
1512 map_.insert(i, nullptr);
1513 }
1514 EXPECT_LT(32ul, map_.Capacity());
1515 }
1516
1517 void Dispose() {
1518 vector_.Clear();
1519 EXPECT_LT(0ul, vector_.Capacity());
1520 for (int i = 1; i <= 32; ++i) {
1521 map_.erase(i);
1522 }
1523 EXPECT_LT(32ul, map_.Capacity());
1524 // Clearing is OK inside a pre finalizer.
1525 map_.Clear();
1526 EXPECT_EQ(0ul, map_.Capacity());
1527 }
1528
1529 DEFINE_INLINE_TRACE() {
1530 visitor->Trace(vector_);
1531 visitor->Trace(map_);
1532 }
1533
1534 private:
1535 HeapVector<Member<IntWrapper>> vector_;
1536 HeapHashMap<int, Member<IntWrapper>> map_;
1537 };
1538
1539 TEST(HeapTest, BackingReallocationForbidden) {
1540 new PreFinalizerBackingReallocationForbiddenCheck();
1541 PreciselyCollectGarbage();
1542 }
1543
1502 TEST(HeapTest, Transition) { 1544 TEST(HeapTest, Transition) {
1503 { 1545 {
1504 RefCountedAndGarbageCollected::destructor_calls_ = 0; 1546 RefCountedAndGarbageCollected::destructor_calls_ = 0;
1505 Persistent<RefCountedAndGarbageCollected> ref_counted = 1547 Persistent<RefCountedAndGarbageCollected> ref_counted =
1506 RefCountedAndGarbageCollected::Create(); 1548 RefCountedAndGarbageCollected::Create();
1507 PreciselyCollectGarbage(); 1549 PreciselyCollectGarbage();
1508 EXPECT_EQ(0, RefCountedAndGarbageCollected::destructor_calls_); 1550 EXPECT_EQ(0, RefCountedAndGarbageCollected::destructor_calls_);
1509 } 1551 }
1510 PreciselyCollectGarbage(); 1552 PreciselyCollectGarbage();
1511 EXPECT_EQ(1, RefCountedAndGarbageCollected::destructor_calls_); 1553 EXPECT_EQ(1, RefCountedAndGarbageCollected::destructor_calls_);
(...skipping 5044 matching lines...) Expand 10 before | Expand all | Expand 10 after
6556 map.insert(key, IntWrapper::Create(i)); 6598 map.insert(key, IntWrapper::Create(i));
6557 } 6599 }
6558 6600
6559 EXPECT_FALSE(string.Impl()->HasOneRef()); 6601 EXPECT_FALSE(string.Impl()->HasOneRef());
6560 map.Clear(); 6602 map.Clear();
6561 6603
6562 EXPECT_TRUE(string.Impl()->HasOneRef()); 6604 EXPECT_TRUE(string.Impl()->HasOneRef());
6563 } 6605 }
6564 6606
6565 } // namespace blink 6607 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698