| 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 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 | 911 |
| 912 void ThreadState::preGC() | 912 void ThreadState::preGC() |
| 913 { | 913 { |
| 914 ASSERT(!isInGC()); | 914 ASSERT(!isInGC()); |
| 915 setGCState(GCRunning); | 915 setGCState(GCRunning); |
| 916 makeConsistentForSweeping(); | 916 makeConsistentForSweeping(); |
| 917 prepareRegionTree(); | 917 prepareRegionTree(); |
| 918 flushHeapDoesNotContainCacheIfNeeded(); | 918 flushHeapDoesNotContainCacheIfNeeded(); |
| 919 if (isMainThread()) | 919 if (isMainThread()) |
| 920 m_allocatedObjectSizeBeforeGC = Heap::allocatedObjectSize() + Heap::mark
edObjectSize(); | 920 m_allocatedObjectSizeBeforeGC = Heap::allocatedObjectSize() + Heap::mark
edObjectSize(); |
| 921 invokePreMarkingTasks(); |
| 921 } | 922 } |
| 922 | 923 |
| 923 void ThreadState::postGC(GCType gcType) | 924 void ThreadState::postGC(GCType gcType) |
| 924 { | 925 { |
| 925 ASSERT(isInGC()); | 926 ASSERT(isInGC()); |
| 926 | 927 |
| 927 #if ENABLE(GC_PROFILING) | 928 #if ENABLE(GC_PROFILING) |
| 928 // We snapshot the heap prior to sweeping to get numbers for both resources | 929 // We snapshot the heap prior to sweeping to get numbers for both resources |
| 929 // that have been allocated since the last GC and for resources that are | 930 // that have been allocated since the last GC and for resources that are |
| 930 // going to be freed. | 931 // going to be freed. |
| 931 bool gcTracingEnabled; | 932 bool gcTracingEnabled; |
| 932 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); | 933 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); |
| 933 | 934 |
| 934 if (gcTracingEnabled) { | 935 if (gcTracingEnabled) { |
| 935 bool disabledByDefaultGCTracingEnabled; | 936 bool disabledByDefaultGCTracingEnabled; |
| 936 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc")
, &disabledByDefaultGCTracingEnabled); | 937 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc")
, &disabledByDefaultGCTracingEnabled); |
| 937 | 938 |
| 938 snapshot(); | 939 snapshot(); |
| 939 if (disabledByDefaultGCTracingEnabled) | 940 if (disabledByDefaultGCTracingEnabled) |
| 940 collectAndReportMarkSweepStats(); | 941 collectAndReportMarkSweepStats(); |
| 941 incrementMarkedObjectsAge(); | 942 incrementMarkedObjectsAge(); |
| 942 } | 943 } |
| 943 #endif | 944 #endif |
| 944 | 945 |
| 946 invokePostMarkingTasks(); |
| 945 setGCState(gcType == GCWithSweep ? EagerSweepScheduled : LazySweepScheduled)
; | 947 setGCState(gcType == GCWithSweep ? EagerSweepScheduled : LazySweepScheduled)
; |
| 946 for (int i = 0; i < NumberOfHeaps; i++) | 948 for (int i = 0; i < NumberOfHeaps; i++) |
| 947 m_heaps[i]->prepareForSweep(); | 949 m_heaps[i]->prepareForSweep(); |
| 948 } | 950 } |
| 949 | 951 |
| 952 void ThreadState::invokePreMarkingTasks() |
| 953 { |
| 954 ASSERT(isInGC()); |
| 955 for (MarkingTask* task : m_markingTasks) |
| 956 task->willStartMarking(*this); |
| 957 } |
| 958 |
| 959 void ThreadState::invokePostMarkingTasks() |
| 960 { |
| 961 ASSERT(isInGC()); |
| 962 for (size_t i = m_markingTasks.size(); i > 0; --i) |
| 963 m_markingTasks[i - 1]->didFinishMarking(*this); |
| 964 } |
| 965 |
| 966 void ThreadState::addMarkingTask(MarkingTask* task) |
| 967 { |
| 968 ASSERT(!isInGC()); |
| 969 checkThread(); |
| 970 m_markingTasks.append(task); |
| 971 } |
| 972 |
| 973 void ThreadState::removeMarkingTask(MarkingTask* task) |
| 974 { |
| 975 ASSERT(!isInGC()); |
| 976 checkThread(); |
| 977 size_t position = m_markingTasks.find(task); |
| 978 ASSERT(position != kNotFound); |
| 979 m_markingTasks.remove(position); |
| 980 } |
| 981 |
| 950 void ThreadState::prepareHeapForTermination() | 982 void ThreadState::prepareHeapForTermination() |
| 951 { | 983 { |
| 952 checkThread(); | 984 checkThread(); |
| 953 for (int i = 0; i < NumberOfHeaps; ++i) | 985 for (int i = 0; i < NumberOfHeaps; ++i) |
| 954 m_heaps[i]->prepareHeapForTermination(); | 986 m_heaps[i]->prepareHeapForTermination(); |
| 955 } | 987 } |
| 956 | 988 |
| 957 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) | 989 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) |
| 958 BasePage* ThreadState::findPageFromAddress(Address address) | 990 BasePage* ThreadState::findPageFromAddress(Address address) |
| 959 { | 991 { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing
"); | 1126 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing
"); |
| 1095 // Perform thread-specific weak processing. | 1127 // Perform thread-specific weak processing. |
| 1096 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor))
{ } | 1128 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor))
{ } |
| 1097 } | 1129 } |
| 1098 { | 1130 { |
| 1099 TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers"); | 1131 TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers"); |
| 1100 invokePreFinalizers(*Heap::s_markingVisitor); | 1132 invokePreFinalizers(*Heap::s_markingVisitor); |
| 1101 } | 1133 } |
| 1102 } | 1134 } |
| 1103 | 1135 |
| 1136 if (!m_zombies.isEmpty()) { |
| 1137 TRACE_EVENT0("blink_gc", "Heap::visitObjects"); |
| 1138 // The following marking should not run in multiple threads because |
| 1139 // it uses global resources such as s_markingStack. |
| 1140 SafePointAwareMutexLocker locker(threadAttachMutex(), NoHeapPointers
OnStack); |
| 1141 GCState originalState = gcState(); |
| 1142 setGCState(GCRunning); |
| 1143 invokePreMarkingTasks(); |
| 1144 Heap::visitObjects(this, m_zombies); |
| 1145 invokePostMarkingTasks(); |
| 1146 setGCState(originalState); |
| 1147 } |
| 1148 |
| 1104 if (isMainThread()) | 1149 if (isMainThread()) |
| 1105 ScriptForbiddenScope::exit(); | 1150 ScriptForbiddenScope::exit(); |
| 1106 } | 1151 } |
| 1107 | 1152 |
| 1108 #if ENABLE(OILPAN) | 1153 #if ENABLE(OILPAN) |
| 1109 if (gcState() == EagerSweepScheduled) { | 1154 if (gcState() == EagerSweepScheduled) { |
| 1110 // Eager sweeping should happen only in testing. | 1155 // Eager sweeping should happen only in testing. |
| 1111 setGCState(Sweeping); | 1156 setGCState(Sweeping); |
| 1112 completeSweep(); | 1157 completeSweep(); |
| 1113 } else { | 1158 } else { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 checkThread(); | 1222 checkThread(); |
| 1178 Vector<void*> deadObjects; | 1223 Vector<void*> deadObjects; |
| 1179 for (auto& entry : m_preFinalizers) { | 1224 for (auto& entry : m_preFinalizers) { |
| 1180 if (entry.value(entry.key, visitor)) | 1225 if (entry.value(entry.key, visitor)) |
| 1181 deadObjects.append(entry.key); | 1226 deadObjects.append(entry.key); |
| 1182 } | 1227 } |
| 1183 // FIXME: removeAll is inefficient. It can shrink repeatedly. | 1228 // FIXME: removeAll is inefficient. It can shrink repeatedly. |
| 1184 m_preFinalizers.removeAll(deadObjects); | 1229 m_preFinalizers.removeAll(deadObjects); |
| 1185 } | 1230 } |
| 1186 | 1231 |
| 1232 void ThreadState::markAsZombie(void* object) |
| 1233 { |
| 1234 ASSERT(!isInGC()); |
| 1235 checkThread(); |
| 1236 ASSERT(!m_zombies.contains(object)); |
| 1237 m_zombies.add(object); |
| 1238 } |
| 1239 |
| 1240 void ThreadState::purifyZombies() |
| 1241 { |
| 1242 m_zombies.clear(); |
| 1243 } |
| 1244 |
| 1187 #if ENABLE(GC_PROFILING) | 1245 #if ENABLE(GC_PROFILING) |
| 1188 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) | 1246 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) |
| 1189 { | 1247 { |
| 1190 bool needLockForIteration = !ThreadState::current()->isInGC(); | 1248 bool needLockForIteration = !ThreadState::current()->isInGC(); |
| 1191 if (needLockForIteration) | 1249 if (needLockForIteration) |
| 1192 threadAttachMutex().lock(); | 1250 threadAttachMutex().lock(); |
| 1193 | 1251 |
| 1194 for (ThreadState* state : attachedThreads()) { | 1252 for (ThreadState* state : attachedThreads()) { |
| 1195 if (const GCInfo* gcInfo = state->findGCInfo(address)) { | 1253 if (const GCInfo* gcInfo = state->findGCInfo(address)) { |
| 1196 if (needLockForIteration) | 1254 if (needLockForIteration) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 json->beginArray(it->key.ascii().data()); | 1325 json->beginArray(it->key.ascii().data()); |
| 1268 for (size_t age = 0; age <= maxHeapObjectAge; ++age) | 1326 for (size_t age = 0; age <= maxHeapObjectAge; ++age) |
| 1269 json->pushInteger(it->value.ages[age]); | 1327 json->pushInteger(it->value.ages[age]); |
| 1270 json->endArray(); | 1328 json->endArray(); |
| 1271 } | 1329 } |
| 1272 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s
tatsName, this, json.release()); | 1330 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s
tatsName, this, json.release()); |
| 1273 } | 1331 } |
| 1274 #endif | 1332 #endif |
| 1275 | 1333 |
| 1276 } // namespace blink | 1334 } // namespace blink |
| OLD | NEW |