Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(917)

Side by Side Diff: Source/platform/heap/ThreadState.cpp

Issue 940963005: Revert of WebAudio: Fix AudioNode leak in a case that AudioNode is not disconnected from the ... (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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();
922 } 921 }
923 922
924 void ThreadState::postGC(GCType gcType) 923 void ThreadState::postGC(GCType gcType)
925 { 924 {
926 ASSERT(isInGC()); 925 ASSERT(isInGC());
927 926
928 #if ENABLE(GC_PROFILING) 927 #if ENABLE(GC_PROFILING)
929 // We snapshot the heap prior to sweeping to get numbers for both resources 928 // We snapshot the heap prior to sweeping to get numbers for both resources
930 // that have been allocated since the last GC and for resources that are 929 // that have been allocated since the last GC and for resources that are
931 // going to be freed. 930 // going to be freed.
932 bool gcTracingEnabled; 931 bool gcTracingEnabled;
933 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); 932 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled);
934 933
935 if (gcTracingEnabled) { 934 if (gcTracingEnabled) {
936 bool disabledByDefaultGCTracingEnabled; 935 bool disabledByDefaultGCTracingEnabled;
937 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc") , &disabledByDefaultGCTracingEnabled); 936 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc") , &disabledByDefaultGCTracingEnabled);
938 937
939 snapshot(); 938 snapshot();
940 if (disabledByDefaultGCTracingEnabled) 939 if (disabledByDefaultGCTracingEnabled)
941 collectAndReportMarkSweepStats(); 940 collectAndReportMarkSweepStats();
942 incrementMarkedObjectsAge(); 941 incrementMarkedObjectsAge();
943 } 942 }
944 #endif 943 #endif
945 944
946 invokePostMarkingTasks();
947 setGCState(gcType == GCWithSweep ? EagerSweepScheduled : LazySweepScheduled) ; 945 setGCState(gcType == GCWithSweep ? EagerSweepScheduled : LazySweepScheduled) ;
948 for (int i = 0; i < NumberOfHeaps; i++) 946 for (int i = 0; i < NumberOfHeaps; i++)
949 m_heaps[i]->prepareForSweep(); 947 m_heaps[i]->prepareForSweep();
950 } 948 }
951 949
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
982 void ThreadState::prepareHeapForTermination() 950 void ThreadState::prepareHeapForTermination()
983 { 951 {
984 checkThread(); 952 checkThread();
985 for (int i = 0; i < NumberOfHeaps; ++i) 953 for (int i = 0; i < NumberOfHeaps; ++i)
986 m_heaps[i]->prepareHeapForTermination(); 954 m_heaps[i]->prepareHeapForTermination();
987 } 955 }
988 956
989 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) 957 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING)
990 BasePage* ThreadState::findPageFromAddress(Address address) 958 BasePage* ThreadState::findPageFromAddress(Address address)
991 { 959 {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing "); 1094 TRACE_EVENT0("blink_gc", "ThreadState::threadLocalWeakProcessing ");
1127 // Perform thread-specific weak processing. 1095 // Perform thread-specific weak processing.
1128 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor)) { } 1096 while (popAndInvokeWeakPointerCallback(Heap::s_markingVisitor)) { }
1129 } 1097 }
1130 { 1098 {
1131 TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers"); 1099 TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers");
1132 invokePreFinalizers(*Heap::s_markingVisitor); 1100 invokePreFinalizers(*Heap::s_markingVisitor);
1133 } 1101 }
1134 } 1102 }
1135 1103
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
1149 if (isMainThread()) 1104 if (isMainThread())
1150 ScriptForbiddenScope::exit(); 1105 ScriptForbiddenScope::exit();
1151 } 1106 }
1152 1107
1153 #if ENABLE(OILPAN) 1108 #if ENABLE(OILPAN)
1154 if (gcState() == EagerSweepScheduled) { 1109 if (gcState() == EagerSweepScheduled) {
1155 // Eager sweeping should happen only in testing. 1110 // Eager sweeping should happen only in testing.
1156 setGCState(Sweeping); 1111 setGCState(Sweeping);
1157 completeSweep(); 1112 completeSweep();
1158 } else { 1113 } else {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 checkThread(); 1177 checkThread();
1223 Vector<void*> deadObjects; 1178 Vector<void*> deadObjects;
1224 for (auto& entry : m_preFinalizers) { 1179 for (auto& entry : m_preFinalizers) {
1225 if (entry.value(entry.key, visitor)) 1180 if (entry.value(entry.key, visitor))
1226 deadObjects.append(entry.key); 1181 deadObjects.append(entry.key);
1227 } 1182 }
1228 // FIXME: removeAll is inefficient. It can shrink repeatedly. 1183 // FIXME: removeAll is inefficient. It can shrink repeatedly.
1229 m_preFinalizers.removeAll(deadObjects); 1184 m_preFinalizers.removeAll(deadObjects);
1230 } 1185 }
1231 1186
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
1245 #if ENABLE(GC_PROFILING) 1187 #if ENABLE(GC_PROFILING)
1246 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) 1188 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address)
1247 { 1189 {
1248 bool needLockForIteration = !ThreadState::current()->isInGC(); 1190 bool needLockForIteration = !ThreadState::current()->isInGC();
1249 if (needLockForIteration) 1191 if (needLockForIteration)
1250 threadAttachMutex().lock(); 1192 threadAttachMutex().lock();
1251 1193
1252 for (ThreadState* state : attachedThreads()) { 1194 for (ThreadState* state : attachedThreads()) {
1253 if (const GCInfo* gcInfo = state->findGCInfo(address)) { 1195 if (const GCInfo* gcInfo = state->findGCInfo(address)) {
1254 if (needLockForIteration) 1196 if (needLockForIteration)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 json->beginArray(it->key.ascii().data()); 1267 json->beginArray(it->key.ascii().data());
1326 for (size_t age = 0; age <= maxHeapObjectAge; ++age) 1268 for (size_t age = 0; age <= maxHeapObjectAge; ++age)
1327 json->pushInteger(it->value.ages[age]); 1269 json->pushInteger(it->value.ages[age]);
1328 json->endArray(); 1270 json->endArray();
1329 } 1271 }
1330 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release()); 1272 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release());
1331 } 1273 }
1332 #endif 1274 #endif
1333 1275
1334 } // namespace blink 1276 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698