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

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

Issue 1155113002: Oilpan: HeapObjectHeader::checkHeader should not allow access on orphaned pages (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 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 | « Source/platform/heap/Heap.h ('k') | Source/platform/heap/HeapAllocator.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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 598 }
599 if (header->isFree()) { 599 if (header->isFree()) {
600 // Zero the memory in the free list header to maintain the 600 // Zero the memory in the free list header to maintain the
601 // invariant that memory on the free list is zero filled. 601 // invariant that memory on the free list is zero filled.
602 // The rest of the memory is already on the free list and is 602 // The rest of the memory is already on the free list and is
603 // therefore already zero filled. 603 // therefore already zero filled.
604 FILL_ZERO_IF_PRODUCTION(headerAddress, size < sizeof(FreeListEnt ry) ? size : sizeof(FreeListEntry)); 604 FILL_ZERO_IF_PRODUCTION(headerAddress, size < sizeof(FreeListEnt ry) ? size : sizeof(FreeListEntry));
605 headerAddress += size; 605 headerAddress += size;
606 continue; 606 continue;
607 } 607 }
608 header->checkHeader();
608 if (startOfGap != headerAddress) 609 if (startOfGap != headerAddress)
609 addToFreeList(startOfGap, headerAddress - startOfGap); 610 addToFreeList(startOfGap, headerAddress - startOfGap);
610 611
611 headerAddress += size; 612 headerAddress += size;
612 startOfGap = headerAddress; 613 startOfGap = headerAddress;
613 } 614 }
614 615
615 if (startOfGap != page->payloadEnd()) 616 if (startOfGap != page->payloadEnd())
616 addToFreeList(startOfGap, page->payloadEnd() - startOfGap); 617 addToFreeList(startOfGap, page->payloadEnd() - startOfGap);
617 } 618 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 } 652 }
652 653
653 m_promptlyFreedSize += size; 654 m_promptlyFreedSize += size;
654 } 655 }
655 656
656 bool NormalPageHeap::expandObject(HeapObjectHeader* header, size_t newSize) 657 bool NormalPageHeap::expandObject(HeapObjectHeader* header, size_t newSize)
657 { 658 {
658 // It's possible that Vector requests a smaller expanded size because 659 // It's possible that Vector requests a smaller expanded size because
659 // Vector::shrinkCapacity can set a capacity smaller than the actual payload 660 // Vector::shrinkCapacity can set a capacity smaller than the actual payload
660 // size. 661 // size.
662 header->checkHeader();
661 if (header->payloadSize() >= newSize) 663 if (header->payloadSize() >= newSize)
662 return true; 664 return true;
663 size_t allocationSize = Heap::allocationSizeFromSize(newSize); 665 size_t allocationSize = Heap::allocationSizeFromSize(newSize);
664 ASSERT(allocationSize > header->size()); 666 ASSERT(allocationSize > header->size());
665 size_t expandSize = allocationSize - header->size(); 667 size_t expandSize = allocationSize - header->size();
666 if (header->payloadEnd() == m_currentAllocationPoint && expandSize <= m_rema iningAllocationSize) { 668 if (header->payloadEnd() == m_currentAllocationPoint && expandSize <= m_rema iningAllocationSize) {
667 m_currentAllocationPoint += expandSize; 669 m_currentAllocationPoint += expandSize;
668 m_remainingAllocationSize -= expandSize; 670 m_remainingAllocationSize -= expandSize;
669 671
670 // Unpoison the memory used for the object (payload). 672 // Unpoison the memory used for the object (payload).
671 ASAN_UNPOISON_MEMORY_REGION(header->payloadEnd(), expandSize); 673 ASAN_UNPOISON_MEMORY_REGION(header->payloadEnd(), expandSize);
672 FILL_ZERO_IF_NOT_PRODUCTION(header->payloadEnd(), expandSize); 674 FILL_ZERO_IF_NOT_PRODUCTION(header->payloadEnd(), expandSize);
673 header->setSize(allocationSize); 675 header->setSize(allocationSize);
674 ASSERT(findPageFromAddress(header->payloadEnd() - 1)); 676 ASSERT(findPageFromAddress(header->payloadEnd() - 1));
675 return true; 677 return true;
676 } 678 }
677 return false; 679 return false;
678 } 680 }
679 681
680 bool NormalPageHeap::shrinkObject(HeapObjectHeader* header, size_t newSize) 682 bool NormalPageHeap::shrinkObject(HeapObjectHeader* header, size_t newSize)
681 { 683 {
684 header->checkHeader();
682 ASSERT(header->payloadSize() > newSize); 685 ASSERT(header->payloadSize() > newSize);
683 size_t allocationSize = Heap::allocationSizeFromSize(newSize); 686 size_t allocationSize = Heap::allocationSizeFromSize(newSize);
684 ASSERT(header->size() > allocationSize); 687 ASSERT(header->size() > allocationSize);
685 size_t shrinkSize = header->size() - allocationSize; 688 size_t shrinkSize = header->size() - allocationSize;
686 if (header->payloadEnd() == m_currentAllocationPoint) { 689 if (header->payloadEnd() == m_currentAllocationPoint) {
687 m_currentAllocationPoint -= shrinkSize; 690 m_currentAllocationPoint -= shrinkSize;
688 m_remainingAllocationSize += shrinkSize; 691 m_remainingAllocationSize += shrinkSize;
689 FILL_ZERO_IF_PRODUCTION(m_currentAllocationPoint, shrinkSize); 692 FILL_ZERO_IF_PRODUCTION(m_currentAllocationPoint, shrinkSize);
690 ASAN_POISON_MEMORY_REGION(m_currentAllocationPoint, shrinkSize); 693 ASAN_POISON_MEMORY_REGION(m_currentAllocationPoint, shrinkSize);
691 header->setSize(allocationSize); 694 header->setSize(allocationSize);
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 for (size_t i = 0; i < objectSize / sizeof(Address); ++i) { 1276 for (size_t i = 0; i < objectSize / sizeof(Address); ++i) {
1274 if (objectFields[i] != 0) 1277 if (objectFields[i] != 0)
1275 return false; 1278 return false;
1276 } 1279 }
1277 return true; 1280 return true;
1278 } 1281 }
1279 #endif 1282 #endif
1280 1283
1281 static void markPointer(Visitor* visitor, HeapObjectHeader* header) 1284 static void markPointer(Visitor* visitor, HeapObjectHeader* header)
1282 { 1285 {
1286 header->checkHeader();
1283 const GCInfo* gcInfo = Heap::gcInfo(header->gcInfoIndex()); 1287 const GCInfo* gcInfo = Heap::gcInfo(header->gcInfoIndex());
1284 if (gcInfo->hasVTable() && !vTableInitialized(header->payload())) { 1288 if (gcInfo->hasVTable() && !vTableInitialized(header->payload())) {
1285 // We hit this branch when a GC strikes before GarbageCollected<>'s 1289 // We hit this branch when a GC strikes before GarbageCollected<>'s
1286 // constructor runs. 1290 // constructor runs.
1287 // 1291 //
1288 // class A : public GarbageCollected<A> { virtual void f() = 0; }; 1292 // class A : public GarbageCollected<A> { virtual void f() = 0; };
1289 // class B : public A { 1293 // class B : public A {
1290 // B() : A(foo()) { }; 1294 // B() : A(foo()) { };
1291 // }; 1295 // };
1292 // 1296 //
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 { 1348 {
1345 HeapObjectHeader* header = nullptr; 1349 HeapObjectHeader* header = nullptr;
1346 for (Address addr = payload(); addr < payloadEnd(); addr += header->size()) { 1350 for (Address addr = payload(); addr < payloadEnd(); addr += header->size()) {
1347 header = reinterpret_cast<HeapObjectHeader*>(addr); 1351 header = reinterpret_cast<HeapObjectHeader*>(addr);
1348 if (json) 1352 if (json)
1349 json->pushInteger(header->encodedSize()); 1353 json->pushInteger(header->encodedSize());
1350 if (header->isFree()) { 1354 if (header->isFree()) {
1351 info->freeSize += header->size(); 1355 info->freeSize += header->size();
1352 continue; 1356 continue;
1353 } 1357 }
1358 header->checkHeader();
1354 1359
1355 size_t tag = info->getClassTag(Heap::gcInfo(header->gcInfoIndex())); 1360 size_t tag = info->getClassTag(Heap::gcInfo(header->gcInfoIndex()));
1356 size_t age = header->age(); 1361 size_t age = header->age();
1357 if (json) 1362 if (json)
1358 json->pushInteger(tag); 1363 json->pushInteger(tag);
1359 if (header->isMarked()) { 1364 if (header->isMarked()) {
1360 info->liveCount[tag] += 1; 1365 info->liveCount[tag] += 1;
1361 info->liveSize[tag] += header->size(); 1366 info->liveSize[tag] += header->size();
1362 // Count objects that are live when promoted to the final generation . 1367 // Count objects that are live when promoted to the final generation .
1363 if (age == maxHeapObjectAge - 1) 1368 if (age == maxHeapObjectAge - 1)
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 size_t Heap::s_allocatedObjectSize = 0; 2231 size_t Heap::s_allocatedObjectSize = 0;
2227 size_t Heap::s_allocatedSpace = 0; 2232 size_t Heap::s_allocatedSpace = 0;
2228 size_t Heap::s_markedObjectSize = 0; 2233 size_t Heap::s_markedObjectSize = 0;
2229 // We don't want to use 0 KB for the initial value because it may end up 2234 // We don't want to use 0 KB for the initial value because it may end up
2230 // triggering the first GC of some thread too prematurely. 2235 // triggering the first GC of some thread too prematurely.
2231 size_t Heap::s_estimatedLiveObjectSize = 512 * 1024; 2236 size_t Heap::s_estimatedLiveObjectSize = 512 * 1024;
2232 size_t Heap::s_externalObjectSizeAtLastGC = 0; 2237 size_t Heap::s_externalObjectSizeAtLastGC = 0;
2233 double Heap::s_estimatedMarkingTimePerByte = 0.0; 2238 double Heap::s_estimatedMarkingTimePerByte = 0.0;
2234 2239
2235 } // namespace blink 2240 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/platform/heap/HeapAllocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698