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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 void ThreadState::detach() | 471 void ThreadState::detach() |
472 { | 472 { |
473 ThreadState* state = current(); | 473 ThreadState* state = current(); |
474 state->cleanup(); | 474 state->cleanup(); |
475 delete state; | 475 delete state; |
476 shutdownHeapIfNecessary(); | 476 shutdownHeapIfNecessary(); |
477 } | 477 } |
478 | 478 |
479 void ThreadState::visitPersistentRoots(Visitor* visitor) | 479 void ThreadState::visitPersistentRoots(Visitor* visitor) |
480 { | 480 { |
| 481 TRACE_EVENT0("blink_gc", "ThreadState::visitPersistentRoots"); |
481 { | 482 { |
482 // All threads are at safepoints so this is not strictly necessary. | 483 // All threads are at safepoints so this is not strictly necessary. |
483 // However we acquire the mutex to make mutation and traversal of this | 484 // However we acquire the mutex to make mutation and traversal of this |
484 // list symmetrical. | 485 // list symmetrical. |
485 MutexLocker locker(globalRootsMutex()); | 486 MutexLocker locker(globalRootsMutex()); |
486 globalRoots()->trace(visitor); | 487 globalRoots()->trace(visitor); |
487 } | 488 } |
488 | 489 |
489 AttachedThreadStateSet& threads = attachedThreads(); | 490 AttachedThreadStateSet& threads = attachedThreads(); |
490 for (AttachedThreadStateSet::iterator it = threads.begin(), end = threads.en
d(); it != end; ++it) | 491 for (AttachedThreadStateSet::iterator it = threads.begin(), end = threads.en
d(); it != end; ++it) |
491 (*it)->visitPersistents(visitor); | 492 (*it)->visitPersistents(visitor); |
492 } | 493 } |
493 | 494 |
494 void ThreadState::visitStackRoots(Visitor* visitor) | 495 void ThreadState::visitStackRoots(Visitor* visitor) |
495 { | 496 { |
| 497 TRACE_EVENT0("blink_gc", "ThreadState::visitStackRoots"); |
496 AttachedThreadStateSet& threads = attachedThreads(); | 498 AttachedThreadStateSet& threads = attachedThreads(); |
497 for (AttachedThreadStateSet::iterator it = threads.begin(), end = threads.en
d(); it != end; ++it) | 499 for (AttachedThreadStateSet::iterator it = threads.begin(), end = threads.en
d(); it != end; ++it) |
498 (*it)->visitStack(visitor); | 500 (*it)->visitStack(visitor); |
499 } | 501 } |
500 | 502 |
501 NO_SANITIZE_ADDRESS | 503 NO_SANITIZE_ADDRESS |
502 void ThreadState::visitAsanFakeStackForPointer(Visitor* visitor, Address ptr) | 504 void ThreadState::visitAsanFakeStackForPointer(Visitor* visitor, Address ptr) |
503 { | 505 { |
504 #if defined(ADDRESS_SANITIZER) | 506 #if defined(ADDRESS_SANITIZER) |
505 Address* start = reinterpret_cast<Address*>(m_startOfStack); | 507 Address* start = reinterpret_cast<Address*>(m_startOfStack); |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 ScriptForbiddenScope::enter(); | 1091 ScriptForbiddenScope::enter(); |
1090 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkGCSweeping"); | 1092 TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkGCSweeping"); |
1091 } | 1093 } |
1092 | 1094 |
1093 size_t objectSpaceBeforeSweep = m_stats.totalObjectSpace(); | 1095 size_t objectSpaceBeforeSweep = m_stats.totalObjectSpace(); |
1094 { | 1096 { |
1095 NoSweepScope scope(this); | 1097 NoSweepScope scope(this); |
1096 | 1098 |
1097 // Disallow allocation during weak processing. | 1099 // Disallow allocation during weak processing. |
1098 enterNoAllocationScope(); | 1100 enterNoAllocationScope(); |
1099 // Perform thread-specific weak processing. | 1101 { |
1100 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor)) { } | 1102 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing"); |
| 1103 // Perform thread-specific weak processing. |
| 1104 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor)) { } |
| 1105 } |
1101 leaveNoAllocationScope(); | 1106 leaveNoAllocationScope(); |
1102 | 1107 |
1103 // Perform sweeping and finalization. | 1108 // Perform sweeping and finalization. |
1104 | 1109 |
1105 // Sweeping will recalculate the stats | 1110 // Sweeping will recalculate the stats |
1106 m_stats.clear(); | 1111 m_stats.clear(); |
1107 | 1112 |
1108 // Sweep the non-finalized heap pages on multiple threads. | 1113 // Sweep the non-finalized heap pages on multiple threads. |
1109 // Attempt to load-balance by having the sweeper thread sweep as | 1114 // Attempt to load-balance by having the sweeper thread sweep as |
1110 // close to half of the pages as possible. | 1115 // close to half of the pages as possible. |
(...skipping 24 matching lines...) Expand all Loading... |
1135 // sweeper thread and the owner thread. | 1140 // sweeper thread and the owner thread. |
1136 int pagesToSplitOff = std::min(pageCount, pagesToSweepInParallel
); | 1141 int pagesToSplitOff = std::min(pageCount, pagesToSweepInParallel
); |
1137 pagesToSweepInParallel -= pagesToSplitOff; | 1142 pagesToSweepInParallel -= pagesToSplitOff; |
1138 BaseHeap* splitOff = heap->split(pagesToSplitOff); | 1143 BaseHeap* splitOff = heap->split(pagesToSplitOff); |
1139 splitOffHeaps[i] = splitOff; | 1144 splitOffHeaps[i] = splitOff; |
1140 HeapStats* stats = &heapStatsVector[i]; | 1145 HeapStats* stats = &heapStatsVector[i]; |
1141 m_sweeperThread->postTask(new SweepNonFinalizedHeapTask(this, sp
litOff, stats)); | 1146 m_sweeperThread->postTask(new SweepNonFinalizedHeapTask(this, sp
litOff, stats)); |
1142 } | 1147 } |
1143 } | 1148 } |
1144 | 1149 |
1145 // Sweep the remainder of the non-finalized pages (or all of them | 1150 { |
1146 // if there is no sweeper thread). | 1151 // Sweep the remainder of the non-finalized pages (or all of them |
1147 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { | 1152 // if there is no sweeper thread). |
1148 HeapStats stats; | 1153 TRACE_EVENT0("blink_gc", "ThreadState::sweepNonFinalizedHeaps"); |
1149 m_heaps[FirstNonFinalizedHeap + i]->sweep(&stats); | 1154 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { |
1150 m_stats.add(&stats); | 1155 HeapStats stats; |
| 1156 m_heaps[FirstNonFinalizedHeap + i]->sweep(&stats); |
| 1157 m_stats.add(&stats); |
| 1158 } |
1151 } | 1159 } |
1152 | 1160 |
1153 // Sweep the finalized pages. | 1161 { |
1154 for (int i = 0; i < NumberOfFinalizedHeaps; i++) { | 1162 // Sweep the finalized pages. |
1155 HeapStats stats; | 1163 TRACE_EVENT0("blink_gc", "ThreadState::sweepFinalizedHeaps"); |
1156 m_heaps[FirstFinalizedHeap + i]->sweep(&stats); | 1164 for (int i = 0; i < NumberOfFinalizedHeaps; i++) { |
1157 m_stats.add(&stats); | 1165 HeapStats stats; |
| 1166 m_heaps[FirstFinalizedHeap + i]->sweep(&stats); |
| 1167 m_stats.add(&stats); |
| 1168 } |
1158 } | 1169 } |
1159 | 1170 |
1160 // Wait for the sweeper threads and update the heap stats with the | 1171 // Wait for the sweeper threads and update the heap stats with the |
1161 // stats for the heap portions swept by those threads. | 1172 // stats for the heap portions swept by those threads. |
1162 waitUntilSweepersDone(); | 1173 waitUntilSweepersDone(); |
1163 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { | 1174 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { |
1164 m_stats.add(&heapStatsVector[i]); | 1175 m_stats.add(&heapStatsVector[i]); |
1165 if (BaseHeap* splitOff = splitOffHeaps[i]) | 1176 if (BaseHeap* splitOff = splitOffHeaps[i]) |
1166 m_heaps[FirstNonFinalizedHeap + i]->merge(splitOff); | 1177 m_heaps[FirstNonFinalizedHeap + i]->merge(splitOff); |
1167 } | 1178 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 return gcInfo; | 1251 return gcInfo; |
1241 } | 1252 } |
1242 } | 1253 } |
1243 if (needLockForIteration) | 1254 if (needLockForIteration) |
1244 threadAttachMutex().unlock(); | 1255 threadAttachMutex().unlock(); |
1245 return 0; | 1256 return 0; |
1246 } | 1257 } |
1247 #endif | 1258 #endif |
1248 | 1259 |
1249 } | 1260 } |
OLD | NEW |