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 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 | 978 |
979 void ThreadState::preGC() | 979 void ThreadState::preGC() |
980 { | 980 { |
981 ASSERT(!isInGC()); | 981 ASSERT(!isInGC()); |
982 setGCState(GCRunning); | 982 setGCState(GCRunning); |
983 makeConsistentForSweeping(); | 983 makeConsistentForSweeping(); |
984 prepareRegionTree(); | 984 prepareRegionTree(); |
985 flushHeapDoesNotContainCacheIfNeeded(); | 985 flushHeapDoesNotContainCacheIfNeeded(); |
986 if (isMainThread()) | 986 if (isMainThread()) |
987 m_allocatedObjectSizeBeforeGC = Heap::allocatedObjectSize() + Heap::mark
edObjectSize(); | 987 m_allocatedObjectSizeBeforeGC = Heap::allocatedObjectSize() + Heap::mark
edObjectSize(); |
| 988 invokePreMarkingTasks(); |
988 } | 989 } |
989 | 990 |
990 void ThreadState::postGC(GCType gcType) | 991 void ThreadState::postGC(GCType gcType) |
991 { | 992 { |
992 ASSERT(isInGC()); | 993 ASSERT(isInGC()); |
| 994 invokePostMarkingTasks(); |
993 setGCState(gcType == GCWithSweep ? EagerSweepScheduled : LazySweepScheduled)
; | 995 setGCState(gcType == GCWithSweep ? EagerSweepScheduled : LazySweepScheduled)
; |
994 for (int i = 0; i < NumberOfHeaps; i++) | 996 for (int i = 0; i < NumberOfHeaps; i++) |
995 m_heaps[i]->prepareForSweep(); | 997 m_heaps[i]->prepareForSweep(); |
996 } | 998 } |
997 | 999 |
| 1000 void ThreadState::invokePreMarkingTasks() |
| 1001 { |
| 1002 ASSERT(isInGC()); |
| 1003 for (MarkingTask* task : m_markingTasks) |
| 1004 task->willStartMarking(*this); |
| 1005 } |
| 1006 |
| 1007 void ThreadState::invokePostMarkingTasks() |
| 1008 { |
| 1009 ASSERT(isInGC()); |
| 1010 for (size_t i = m_markingTasks.size(); i > 0; --i) |
| 1011 m_markingTasks[i - 1]->didFinishMarking(*this); |
| 1012 } |
| 1013 |
| 1014 void ThreadState::addMarkingTask(MarkingTask* task) |
| 1015 { |
| 1016 ASSERT(!isInGC()); |
| 1017 checkThread(); |
| 1018 m_markingTasks.append(task); |
| 1019 } |
| 1020 |
| 1021 void ThreadState::removeMarkingTask(MarkingTask* task) |
| 1022 { |
| 1023 ASSERT(!isInGC()); |
| 1024 checkThread(); |
| 1025 size_t position = m_markingTasks.find(task); |
| 1026 ASSERT(position != kNotFound); |
| 1027 m_markingTasks.remove(position); |
| 1028 } |
| 1029 |
998 void ThreadState::prepareHeapForTermination() | 1030 void ThreadState::prepareHeapForTermination() |
999 { | 1031 { |
1000 checkThread(); | 1032 checkThread(); |
1001 for (int i = 0; i < NumberOfHeaps; ++i) | 1033 for (int i = 0; i < NumberOfHeaps; ++i) |
1002 m_heaps[i]->prepareHeapForTermination(); | 1034 m_heaps[i]->prepareHeapForTermination(); |
1003 } | 1035 } |
1004 | 1036 |
1005 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) | 1037 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) |
1006 BaseHeapPage* ThreadState::findPageFromAddress(Address address) | 1038 BaseHeapPage* ThreadState::findPageFromAddress(Address address) |
1007 { | 1039 { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing
"); | 1184 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing
"); |
1153 // Perform thread-specific weak processing. | 1185 // Perform thread-specific weak processing. |
1154 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor))
{ } | 1186 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor))
{ } |
1155 } | 1187 } |
1156 { | 1188 { |
1157 TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers"); | 1189 TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers"); |
1158 invokePreFinalizers(*Heap::s_markingVisitor); | 1190 invokePreFinalizers(*Heap::s_markingVisitor); |
1159 } | 1191 } |
1160 } | 1192 } |
1161 | 1193 |
| 1194 if (!m_zombies.isEmpty()) { |
| 1195 TRACE_EVENT0("blink_gc", "Heap::visitObjects"); |
| 1196 // The following marking should not run in multiple threads because |
| 1197 // it uses global resources such as s_markingStack. |
| 1198 SafePointAwareMutexLocker locker(threadAttachMutex(), NoHeapPointers
OnStack); |
| 1199 GCState originalState = gcState(); |
| 1200 setGCState(GCRunning); |
| 1201 invokePreMarkingTasks(); |
| 1202 Heap::visitObjects(this, m_zombies); |
| 1203 invokePostMarkingTasks(); |
| 1204 setGCState(originalState); |
| 1205 } |
| 1206 |
1162 if (isMainThread()) | 1207 if (isMainThread()) |
1163 ScriptForbiddenScope::exit(); | 1208 ScriptForbiddenScope::exit(); |
1164 } | 1209 } |
1165 | 1210 |
1166 #if ENABLE(OILPAN) | 1211 #if ENABLE(OILPAN) |
1167 if (gcState() == EagerSweepScheduled) { | 1212 if (gcState() == EagerSweepScheduled) { |
1168 // Eager sweeping should happen only in testing. | 1213 // Eager sweeping should happen only in testing. |
1169 setGCState(Sweeping); | 1214 setGCState(Sweeping); |
1170 completeSweep(); | 1215 completeSweep(); |
1171 } else { | 1216 } else { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 checkThread(); | 1280 checkThread(); |
1236 Vector<void*> deadObjects; | 1281 Vector<void*> deadObjects; |
1237 for (auto& entry : m_preFinalizers) { | 1282 for (auto& entry : m_preFinalizers) { |
1238 if (entry.value(entry.key, visitor)) | 1283 if (entry.value(entry.key, visitor)) |
1239 deadObjects.append(entry.key); | 1284 deadObjects.append(entry.key); |
1240 } | 1285 } |
1241 // FIXME: removeAll is inefficient. It can shrink repeatedly. | 1286 // FIXME: removeAll is inefficient. It can shrink repeatedly. |
1242 m_preFinalizers.removeAll(deadObjects); | 1287 m_preFinalizers.removeAll(deadObjects); |
1243 } | 1288 } |
1244 | 1289 |
| 1290 void ThreadState::markAsZombie(void* object) |
| 1291 { |
| 1292 ASSERT(!isInGC()); |
| 1293 checkThread(); |
| 1294 ASSERT(!m_zombies.contains(object)); |
| 1295 m_zombies.add(object); |
| 1296 } |
| 1297 |
| 1298 void ThreadState::purifyZombies() |
| 1299 { |
| 1300 m_zombies.clear(); |
| 1301 } |
| 1302 |
1245 #if ENABLE(GC_PROFILING) | 1303 #if ENABLE(GC_PROFILING) |
1246 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) | 1304 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) |
1247 { | 1305 { |
1248 bool needLockForIteration = !ThreadState::current()->isInGC(); | 1306 bool needLockForIteration = !ThreadState::current()->isInGC(); |
1249 if (needLockForIteration) | 1307 if (needLockForIteration) |
1250 threadAttachMutex().lock(); | 1308 threadAttachMutex().lock(); |
1251 | 1309 |
1252 for (ThreadState* state : attachedThreads()) { | 1310 for (ThreadState* state : attachedThreads()) { |
1253 if (const GCInfo* gcInfo = state->findGCInfo(address)) { | 1311 if (const GCInfo* gcInfo = state->findGCInfo(address)) { |
1254 if (needLockForIteration) | 1312 if (needLockForIteration) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 FOR_EACH_TYPED_HEAP(SNAPSHOT_FREE_LIST); | 1354 FOR_EACH_TYPED_HEAP(SNAPSHOT_FREE_LIST); |
1297 json->endArray(); | 1355 json->endArray(); |
1298 | 1356 |
1299 #undef SNAPSHOT_FREE_LIST | 1357 #undef SNAPSHOT_FREE_LIST |
1300 | 1358 |
1301 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "
FreeList", this, json.release()); | 1359 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), "
FreeList", this, json.release()); |
1302 } | 1360 } |
1303 #endif | 1361 #endif |
1304 | 1362 |
1305 } // namespace blink | 1363 } // namespace blink |
OLD | NEW |