Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 void HeapObjectHeader::zapMagic() | 92 void HeapObjectHeader::zapMagic() |
| 93 { | 93 { |
| 94 ASSERT(checkHeader()); | 94 ASSERT(checkHeader()); |
| 95 m_magic = zappedMagic; | 95 m_magic = zappedMagic; |
| 96 } | 96 } |
| 97 #endif | 97 #endif |
| 98 | 98 |
| 99 void HeapObjectHeader::finalize(Address object, size_t objectSize) | 99 void HeapObjectHeader::finalize(Address object, size_t objectSize) |
| 100 { | 100 { |
| 101 const GCInfo* gcInfo = Heap::gcInfo(gcInfoIndex()); | 101 const GCInfo* gcInfo = Heap::gcInfo(gcInfoIndex()); |
| 102 if (gcInfo->hasFinalizer()) | 102 if (!gcInfo) { |
| 103 fprintf(stderr, "gcInfoIndex = %ld\n", gcInfoIndex()); | |
| 104 RELEASE_ASSERT(0); | |
| 105 } | |
| 106 fprintf(stderr, "header=%p gcInfo=%p index=%ld\n", this, gcInfo, gcInfoIndex ()); | |
| 107 if (gcInfo->hasFinalizer()) { | |
|
haraken
2016/02/08 08:34:56
I crash here with the following log:
header=0x307
| |
| 108 fprintf(stderr, "hasFinalizer\n"); | |
| 103 gcInfo->m_finalize(object); | 109 gcInfo->m_finalize(object); |
| 110 } else { | |
| 111 fprintf(stderr, "not hasFinalizer\n"); | |
| 112 } | |
| 104 | 113 |
| 105 ASAN_RETIRE_CONTAINER_ANNOTATION(object, objectSize); | 114 ASAN_RETIRE_CONTAINER_ANNOTATION(object, objectSize); |
| 106 } | 115 } |
| 107 | 116 |
| 108 BaseHeap::BaseHeap(ThreadState* state, int index) | 117 BaseHeap::BaseHeap(ThreadState* state, int index) |
| 109 : m_firstPage(nullptr) | 118 : m_firstPage(nullptr) |
| 110 , m_firstUnsweptPage(nullptr) | 119 , m_firstUnsweptPage(nullptr) |
| 111 , m_threadState(state) | 120 , m_threadState(state) |
| 112 , m_index(index) | 121 , m_index(index) |
| 113 { | 122 { |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1097 { | 1106 { |
| 1098 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(payload()); | 1107 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(payload()); |
| 1099 return header->isFree() && header->size() == payloadSize(); | 1108 return header->isFree() && header->size() == payloadSize(); |
| 1100 } | 1109 } |
| 1101 | 1110 |
| 1102 void NormalPage::removeFromHeap() | 1111 void NormalPage::removeFromHeap() |
| 1103 { | 1112 { |
| 1104 heapForNormalPage()->freePage(this); | 1113 heapForNormalPage()->freePage(this); |
| 1105 } | 1114 } |
| 1106 | 1115 |
| 1116 #if !ENABLE(ASSERT) && !defined(LEAK_SANITIZER) && !defined(ADDRESS_SANITIZER) | |
| 1117 static void discardPages(Address begin, Address end) | |
| 1118 { | |
| 1119 uintptr_t beginAddress = WTF::roundUpToSystemPage(reinterpret_cast<uintptr_t >(begin)); | |
| 1120 uintptr_t endAddress = WTF::roundDownToSystemPage(reinterpret_cast<uintptr_t >(end)); | |
| 1121 fprintf(stderr, "trying to discard %p - %p\n", begin, end); | |
| 1122 if (beginAddress < endAddress) { | |
| 1123 WTF::discardSystemPages(reinterpret_cast<void*>(beginAddress), endAddres s - beginAddress); | |
| 1124 fprintf(stderr, "discarded %lx - %lx size=%ld\n", beginAddress, endAddre ss, endAddress - beginAddress); | |
| 1125 } | |
| 1126 } | |
| 1127 #endif | |
| 1128 | |
| 1107 void NormalPage::sweep() | 1129 void NormalPage::sweep() |
| 1108 { | 1130 { |
| 1109 size_t markedObjectSize = 0; | 1131 size_t markedObjectSize = 0; |
| 1110 Address startOfGap = payload(); | 1132 Address startOfGap = payload(); |
| 1111 for (Address headerAddress = startOfGap; headerAddress < payloadEnd(); ) { | 1133 for (Address headerAddress = startOfGap; headerAddress < payloadEnd(); ) { |
| 1112 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(headerAdd ress); | 1134 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(headerAdd ress); |
| 1113 ASSERT(header->size() > 0); | 1135 size_t size = header->size(); |
| 1114 ASSERT(header->size() < blinkPagePayloadSize()); | 1136 ASSERT(size > 0); |
| 1137 ASSERT(size < blinkPagePayloadSize()); | |
| 1115 | 1138 |
| 1116 if (header->isPromptlyFreed()) | 1139 if (header->isPromptlyFreed()) |
| 1117 heapForNormalPage()->decreasePromptlyFreedSize(header->size()); | 1140 heapForNormalPage()->decreasePromptlyFreedSize(size); |
| 1118 if (header->isFree()) { | 1141 if (header->isFree()) { |
| 1119 size_t size = header->size(); | |
| 1120 // Zero the memory in the free list header to maintain the | 1142 // Zero the memory in the free list header to maintain the |
| 1121 // invariant that memory on the free list is zero filled. | 1143 // invariant that memory on the free list is zero filled. |
| 1122 // The rest of the memory is already on the free list and is | 1144 // The rest of the memory is already on the free list and is |
| 1123 // therefore already zero filled. | 1145 // therefore already zero filled. |
| 1124 SET_MEMORY_INACCESSIBLE(headerAddress, size < sizeof(FreeListEntry) ? size : sizeof(FreeListEntry)); | 1146 SET_MEMORY_INACCESSIBLE(headerAddress, size < sizeof(FreeListEntry) ? size : sizeof(FreeListEntry)); |
| 1125 CHECK_MEMORY_INACCESSIBLE(headerAddress, size); | 1147 CHECK_MEMORY_INACCESSIBLE(headerAddress, size); |
| 1126 headerAddress += size; | 1148 headerAddress += size; |
| 1127 continue; | 1149 continue; |
| 1128 } | 1150 } |
| 1129 ASSERT(header->checkHeader()); | 1151 ASSERT(header->checkHeader()); |
| 1130 | 1152 |
| 1131 if (!header->isMarked()) { | 1153 if (!header->isMarked()) { |
| 1132 size_t size = header->size(); | |
| 1133 // This is a fast version of header->payloadSize(). | 1154 // This is a fast version of header->payloadSize(). |
| 1134 size_t payloadSize = size - sizeof(HeapObjectHeader); | 1155 size_t payloadSize = size - sizeof(HeapObjectHeader); |
| 1135 Address payload = header->payload(); | 1156 Address payload = header->payload(); |
| 1136 // For ASan, unpoison the object before calling the finalizer. The | 1157 // For ASan, unpoison the object before calling the finalizer. The |
| 1137 // finalized object will be zero-filled and poison'ed afterwards. | 1158 // finalized object will be zero-filled and poison'ed afterwards. |
| 1138 // Given all other unmarked objects are poisoned, ASan will detect | 1159 // Given all other unmarked objects are poisoned, ASan will detect |
| 1139 // an error if the finalizer touches any other on-heap object that | 1160 // an error if the finalizer touches any other on-heap object that |
| 1140 // die at the same GC cycle. | 1161 // die at the same GC cycle. |
| 1141 ASAN_UNPOISON_MEMORY_REGION(payload, payloadSize); | 1162 ASAN_UNPOISON_MEMORY_REGION(payload, payloadSize); |
| 1142 header->finalize(payload, payloadSize); | 1163 header->finalize(payload, payloadSize); |
| 1143 // This memory will be added to the freelist. Maintain the invariant | 1164 // This memory will be added to the freelist. Maintain the invariant |
| 1144 // that memory on the freelist is zero filled. | 1165 // that memory on the freelist is zero filled. |
| 1145 SET_MEMORY_INACCESSIBLE(headerAddress, size); | 1166 SET_MEMORY_INACCESSIBLE(headerAddress, size); |
| 1146 headerAddress += size; | 1167 headerAddress += size; |
| 1147 continue; | 1168 continue; |
| 1148 } | 1169 } |
| 1149 if (startOfGap != headerAddress) | 1170 if (startOfGap != headerAddress) { |
| 1150 heapForNormalPage()->addToFreeList(startOfGap, headerAddress - start OfGap); | 1171 heapForNormalPage()->addToFreeList(startOfGap, headerAddress - start OfGap); |
| 1172 #if !ENABLE(ASSERT) && !defined(LEAK_SANITIZER) && !defined(ADDRESS_SANITIZER) | |
| 1173 discardPages(startOfGap, headerAddress); | |
| 1174 #endif | |
| 1175 } | |
| 1151 header->unmark(); | 1176 header->unmark(); |
| 1152 headerAddress += header->size(); | 1177 headerAddress += size; |
| 1153 markedObjectSize += header->size(); | 1178 markedObjectSize += size; |
| 1154 startOfGap = headerAddress; | 1179 startOfGap = headerAddress; |
| 1155 } | 1180 } |
| 1156 if (startOfGap != payloadEnd()) | 1181 if (startOfGap != payloadEnd()) { |
| 1157 heapForNormalPage()->addToFreeList(startOfGap, payloadEnd() - startOfGap ); | 1182 heapForNormalPage()->addToFreeList(startOfGap, payloadEnd() - startOfGap ); |
| 1183 #if !ENABLE(ASSERT) && !defined(LEAK_SANITIZER) && !defined(ADDRESS_SANITIZER) | |
| 1184 discardPages(startOfGap, payloadEnd()); | |
| 1185 #endif | |
| 1186 } | |
| 1158 | 1187 |
| 1159 if (markedObjectSize) | 1188 if (markedObjectSize) |
| 1160 Heap::increaseMarkedObjectSize(markedObjectSize); | 1189 Heap::increaseMarkedObjectSize(markedObjectSize); |
| 1161 } | 1190 } |
| 1162 | 1191 |
| 1163 void NormalPage::makeConsistentForGC() | 1192 void NormalPage::makeConsistentForGC() |
| 1164 { | 1193 { |
| 1165 size_t markedObjectSize = 0; | 1194 size_t markedObjectSize = 0; |
| 1166 for (Address headerAddress = payload(); headerAddress < payloadEnd();) { | 1195 for (Address headerAddress = payload(); headerAddress < payloadEnd();) { |
| 1167 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(headerAdd ress); | 1196 HeapObjectHeader* header = reinterpret_cast<HeapObjectHeader*>(headerAdd ress); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1574 | 1603 |
| 1575 m_hasEntries = true; | 1604 m_hasEntries = true; |
| 1576 size_t index = hash(address); | 1605 size_t index = hash(address); |
| 1577 ASSERT(!(index & 1)); | 1606 ASSERT(!(index & 1)); |
| 1578 Address cachePage = roundToBlinkPageStart(address); | 1607 Address cachePage = roundToBlinkPageStart(address); |
| 1579 m_entries[index + 1] = m_entries[index]; | 1608 m_entries[index + 1] = m_entries[index]; |
| 1580 m_entries[index] = cachePage; | 1609 m_entries[index] = cachePage; |
| 1581 } | 1610 } |
| 1582 | 1611 |
| 1583 } // namespace blink | 1612 } // namespace blink |
| OLD | NEW |