| 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 int currentCount = anchor->numberOfPersistents(); | 448 int currentCount = anchor->numberOfPersistents(); |
| 449 ASSERT(currentCount >= 0); | 449 ASSERT(currentCount >= 0); |
| 450 while (currentCount != oldCount) { | 450 while (currentCount != oldCount) { |
| 451 Heap::collectGarbageForTerminatingThread(this); | 451 Heap::collectGarbageForTerminatingThread(this); |
| 452 oldCount = currentCount; | 452 oldCount = currentCount; |
| 453 currentCount = anchor->numberOfPersistents(); | 453 currentCount = anchor->numberOfPersistents(); |
| 454 } | 454 } |
| 455 // We should not have any persistents left when getting to this point, | 455 // We should not have any persistents left when getting to this point, |
| 456 // if we have it is probably a bug so adding a debug ASSERT to catch thi
s. | 456 // if we have it is probably a bug so adding a debug ASSERT to catch thi
s. |
| 457 ASSERT(!currentCount); | 457 ASSERT(!currentCount); |
| 458 // All of pre-finalizers should be consumed. |
| 459 ASSERT(m_preFinalizers.isEmpty()); |
| 458 | 460 |
| 459 // Add pages to the orphaned page pool to ensure any global GCs from thi
s point | 461 // Add pages to the orphaned page pool to ensure any global GCs from thi
s point |
| 460 // on will not trace objects on this thread's heaps. | 462 // on will not trace objects on this thread's heaps. |
| 461 cleanupPages(); | 463 cleanupPages(); |
| 462 | 464 |
| 463 ASSERT(attachedThreads().contains(this)); | 465 ASSERT(attachedThreads().contains(this)); |
| 464 attachedThreads().remove(this); | 466 attachedThreads().remove(this); |
| 465 } | 467 } |
| 466 | 468 |
| 467 for (size_t i = 0; i < m_cleanupTasks.size(); i++) | 469 for (size_t i = 0; i < m_cleanupTasks.size(); i++) |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 { | 1109 { |
| 1108 NoSweepScope scope(this); | 1110 NoSweepScope scope(this); |
| 1109 | 1111 |
| 1110 // Disallow allocation during weak processing. | 1112 // Disallow allocation during weak processing. |
| 1111 enterNoAllocationScope(); | 1113 enterNoAllocationScope(); |
| 1112 { | 1114 { |
| 1113 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing"); | 1115 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing"); |
| 1114 // Perform thread-specific weak processing. | 1116 // Perform thread-specific weak processing. |
| 1115 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor)) { } | 1117 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor)) { } |
| 1116 } | 1118 } |
| 1119 { |
| 1120 TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers"); |
| 1121 invokePreFinalizers(*Heap::s_markingVisitor); |
| 1122 } |
| 1117 leaveNoAllocationScope(); | 1123 leaveNoAllocationScope(); |
| 1118 | 1124 |
| 1119 // Perform sweeping and finalization. | 1125 // Perform sweeping and finalization. |
| 1120 | 1126 |
| 1121 // Sweeping will recalculate the stats | 1127 // Sweeping will recalculate the stats |
| 1122 m_stats.clear(); | 1128 m_stats.clear(); |
| 1123 | 1129 |
| 1124 // Sweep the non-finalized heap pages on multiple threads. | 1130 // Sweep the non-finalized heap pages on multiple threads. |
| 1125 // Attempt to load-balance by having the sweeper thread sweep as | 1131 // Attempt to load-balance by having the sweeper thread sweep as |
| 1126 // close to half of the pages as possible. | 1132 // close to half of the pages as possible. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 ASSERT(!state->isAtSafePoint()); | 1246 ASSERT(!state->isAtSafePoint()); |
| 1241 state->safePoint(HeapPointersOnStack); | 1247 state->safePoint(HeapPointersOnStack); |
| 1242 } | 1248 } |
| 1243 | 1249 |
| 1244 ThreadState::AttachedThreadStateSet& ThreadState::attachedThreads() | 1250 ThreadState::AttachedThreadStateSet& ThreadState::attachedThreads() |
| 1245 { | 1251 { |
| 1246 DEFINE_STATIC_LOCAL(AttachedThreadStateSet, threads, ()); | 1252 DEFINE_STATIC_LOCAL(AttachedThreadStateSet, threads, ()); |
| 1247 return threads; | 1253 return threads; |
| 1248 } | 1254 } |
| 1249 | 1255 |
| 1256 void ThreadState::unregisterPreFinalizerInternal(void* target) |
| 1257 { |
| 1258 if (isSweepInProgress()) |
| 1259 return; |
| 1260 auto it = m_preFinalizers.find(target); |
| 1261 ASSERT(it != m_preFinalizers.end()); |
| 1262 m_preFinalizers.remove(it); |
| 1263 } |
| 1264 |
| 1265 void ThreadState::invokePreFinalizers(Visitor& visitor) |
| 1266 { |
| 1267 Vector<void*> deadObjects; |
| 1268 for (auto& entry : m_preFinalizers) { |
| 1269 if (entry.value(entry.key, visitor)) |
| 1270 deadObjects.append(entry.key); |
| 1271 } |
| 1272 m_preFinalizers.removeAll(deadObjects); |
| 1273 } |
| 1274 |
| 1250 #if ENABLE(GC_PROFILE_MARKING) | 1275 #if ENABLE(GC_PROFILE_MARKING) |
| 1251 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) | 1276 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) |
| 1252 { | 1277 { |
| 1253 bool needLockForIteration = !isAnyThreadInGC(); | 1278 bool needLockForIteration = !isAnyThreadInGC(); |
| 1254 if (needLockForIteration) | 1279 if (needLockForIteration) |
| 1255 threadAttachMutex().lock(); | 1280 threadAttachMutex().lock(); |
| 1256 | 1281 |
| 1257 ThreadState::AttachedThreadStateSet& threads = attachedThreads(); | 1282 ThreadState::AttachedThreadStateSet& threads = attachedThreads(); |
| 1258 for (ThreadState::AttachedThreadStateSet::iterator it = threads.begin(), end
= threads.end(); it != end; ++it) { | 1283 for (ThreadState::AttachedThreadStateSet::iterator it = threads.begin(), end
= threads.end(); it != end; ++it) { |
| 1259 if (const GCInfo* gcInfo = (*it)->findGCInfo(address)) { | 1284 if (const GCInfo* gcInfo = (*it)->findGCInfo(address)) { |
| 1260 if (needLockForIteration) | 1285 if (needLockForIteration) |
| 1261 threadAttachMutex().unlock(); | 1286 threadAttachMutex().unlock(); |
| 1262 return gcInfo; | 1287 return gcInfo; |
| 1263 } | 1288 } |
| 1264 } | 1289 } |
| 1265 if (needLockForIteration) | 1290 if (needLockForIteration) |
| 1266 threadAttachMutex().unlock(); | 1291 threadAttachMutex().unlock(); |
| 1267 return 0; | 1292 return 0; |
| 1268 } | 1293 } |
| 1269 #endif | 1294 #endif |
| 1270 | 1295 |
| 1271 } | 1296 } |
| OLD | NEW |