| 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 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 for (int i = 0; i < NumberOfFinalizedHeaps; i++) | 1140 for (int i = 0; i < NumberOfFinalizedHeaps; i++) |
| 1141 finalizedPages += m_heaps[FirstFinalizedHeap + i]->normalPageCount(); | 1141 finalizedPages += m_heaps[FirstFinalizedHeap + i]->normalPageCount(); |
| 1142 | 1142 |
| 1143 int pagesToSweepInParallel = nonFinalizedPages < finalizedPages ? nonFinaliz
edPages : ((nonFinalizedPages + finalizedPages) / 2); | 1143 int pagesToSweepInParallel = nonFinalizedPages < finalizedPages ? nonFinaliz
edPages : ((nonFinalizedPages + finalizedPages) / 2); |
| 1144 | 1144 |
| 1145 // Start the sweeper thread for the non finalized heaps. No | 1145 // Start the sweeper thread for the non finalized heaps. No |
| 1146 // finalizers need to run and therefore the pages can be | 1146 // finalizers need to run and therefore the pages can be |
| 1147 // swept on other threads. | 1147 // swept on other threads. |
| 1148 static const int minNumberOfPagesForParallelSweep = 10; | 1148 static const int minNumberOfPagesForParallelSweep = 10; |
| 1149 HeapStats heapStatsVector[NumberOfNonFinalizedHeaps]; | 1149 HeapStats heapStatsVector[NumberOfNonFinalizedHeaps]; |
| 1150 BaseHeap* splitOffHeaps[NumberOfNonFinalizedHeaps] = { 0 }; | 1150 OwnPtr<BaseHeap> splitOffHeaps[NumberOfNonFinalizedHeaps]; |
| 1151 for (int i = 0; i < NumberOfNonFinalizedHeaps && pagesToSweepInParallel > 0;
i++) { | 1151 for (int i = 0; i < NumberOfNonFinalizedHeaps && pagesToSweepInParallel > 0;
i++) { |
| 1152 BaseHeap* heap = m_heaps[FirstNonFinalizedHeap + i]; | 1152 BaseHeap* heap = m_heaps[FirstNonFinalizedHeap + i]; |
| 1153 int pageCount = heap->normalPageCount(); | 1153 int pageCount = heap->normalPageCount(); |
| 1154 // Only use the sweeper thread if it exists and there are | 1154 // Only use the sweeper thread if it exists and there are |
| 1155 // pages to sweep. | 1155 // pages to sweep. |
| 1156 if (m_sweeperThread && pageCount > minNumberOfPagesForParallelSweep) { | 1156 if (m_sweeperThread && pageCount > minNumberOfPagesForParallelSweep) { |
| 1157 // Create a new thread heap instance to make sure that the | 1157 // Create a new thread heap instance to make sure that the |
| 1158 // state modified while sweeping is separate for the | 1158 // state modified while sweeping is separate for the |
| 1159 // sweeper thread and the owner thread. | 1159 // sweeper thread and the owner thread. |
| 1160 int pagesToSplitOff = std::min(pageCount, pagesToSweepInParallel); | 1160 int pagesToSplitOff = std::min(pageCount, pagesToSweepInParallel); |
| 1161 pagesToSweepInParallel -= pagesToSplitOff; | 1161 pagesToSweepInParallel -= pagesToSplitOff; |
| 1162 BaseHeap* splitOff = heap->split(pagesToSplitOff); | 1162 splitOffHeaps[i] = heap->split(pagesToSplitOff); |
| 1163 splitOffHeaps[i] = splitOff; | |
| 1164 HeapStats* stats = &heapStatsVector[i]; | 1163 HeapStats* stats = &heapStatsVector[i]; |
| 1165 m_sweeperThread->postTask(new SweepNonFinalizedHeapTask(this, splitO
ff, stats)); | 1164 m_sweeperThread->postTask(new SweepNonFinalizedHeapTask(this, splitO
ffHeaps[i].get(), stats)); |
| 1166 } | 1165 } |
| 1167 } | 1166 } |
| 1168 | 1167 |
| 1169 { | 1168 { |
| 1170 // Sweep the remainder of the non-finalized pages (or all of them | 1169 // Sweep the remainder of the non-finalized pages (or all of them |
| 1171 // if there is no sweeper thread). | 1170 // if there is no sweeper thread). |
| 1172 TRACE_EVENT0("blink_gc", "ThreadState::sweepNonFinalizedHeaps"); | 1171 TRACE_EVENT0("blink_gc", "ThreadState::sweepNonFinalizedHeaps"); |
| 1173 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { | 1172 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { |
| 1174 HeapStats stats; | 1173 HeapStats stats; |
| 1175 m_heaps[FirstNonFinalizedHeap + i]->sweep(&stats); | 1174 m_heaps[FirstNonFinalizedHeap + i]->sweep(&stats); |
| 1176 m_stats.add(&stats); | 1175 m_stats.add(&stats); |
| 1177 } | 1176 } |
| 1178 } | 1177 } |
| 1179 | 1178 |
| 1180 { | 1179 { |
| 1181 // Sweep the finalized pages. | 1180 // Sweep the finalized pages. |
| 1182 TRACE_EVENT0("blink_gc", "ThreadState::sweepFinalizedHeaps"); | 1181 TRACE_EVENT0("blink_gc", "ThreadState::sweepFinalizedHeaps"); |
| 1183 for (int i = 0; i < NumberOfFinalizedHeaps; i++) { | 1182 for (int i = 0; i < NumberOfFinalizedHeaps; i++) { |
| 1184 HeapStats stats; | 1183 HeapStats stats; |
| 1185 m_heaps[FirstFinalizedHeap + i]->sweep(&stats); | 1184 m_heaps[FirstFinalizedHeap + i]->sweep(&stats); |
| 1186 m_stats.add(&stats); | 1185 m_stats.add(&stats); |
| 1187 } | 1186 } |
| 1188 } | 1187 } |
| 1189 | 1188 |
| 1190 // Wait for the sweeper threads and update the heap stats with the | 1189 // Wait for the sweeper threads and update the heap stats with the |
| 1191 // stats for the heap portions swept by those threads. | 1190 // stats for the heap portions swept by those threads. |
| 1192 waitUntilSweepersDone(); | 1191 waitUntilSweepersDone(); |
| 1193 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { | 1192 for (int i = 0; i < NumberOfNonFinalizedHeaps; i++) { |
| 1194 m_stats.add(&heapStatsVector[i]); | 1193 m_stats.add(&heapStatsVector[i]); |
| 1195 if (BaseHeap* splitOff = splitOffHeaps[i]) | 1194 if (splitOffHeaps[i]) |
| 1196 m_heaps[FirstNonFinalizedHeap + i]->merge(splitOff); | 1195 m_heaps[FirstNonFinalizedHeap + i]->merge(splitOffHeaps[i].release()
); |
| 1197 } | 1196 } |
| 1198 | 1197 |
| 1199 for (int i = 0; i < NumberOfHeaps; i++) | 1198 for (int i = 0; i < NumberOfHeaps; i++) |
| 1200 m_heaps[i]->postSweepProcessing(); | 1199 m_heaps[i]->postSweepProcessing(); |
| 1201 | 1200 |
| 1202 getStats(m_statsAfterLastGC); | 1201 getStats(m_statsAfterLastGC); |
| 1203 } | 1202 } |
| 1204 | 1203 |
| 1205 void ThreadState::addInterruptor(Interruptor* interruptor) | 1204 void ThreadState::addInterruptor(Interruptor* interruptor) |
| 1206 { | 1205 { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 return gcInfo; | 1272 return gcInfo; |
| 1274 } | 1273 } |
| 1275 } | 1274 } |
| 1276 if (needLockForIteration) | 1275 if (needLockForIteration) |
| 1277 threadAttachMutex().unlock(); | 1276 threadAttachMutex().unlock(); |
| 1278 return 0; | 1277 return 0; |
| 1279 } | 1278 } |
| 1280 #endif | 1279 #endif |
| 1281 | 1280 |
| 1282 } | 1281 } |
| OLD | NEW |