Title: [202443] trunk/Source/_javascript_Core
- Revision
- 202443
- Author
- [email protected]
- Date
- 2016-06-24 13:30:04 -0700 (Fri, 24 Jun 2016)
Log Message
Web Inspector: CRASH in backend at Inspector::HeapFrontendDispatcher::garbageCollected + 552 when closing frontend/inspected page
https://bugs.webkit.org/show_bug.cgi?id=159075
<rdar://problem/26094341>
Reviewed by Joseph Pecoraro.
Move the asynchronous work to a task class that can be cancelled when the
heap agent is reset, disabled or destroyed.
* inspector/agents/InspectorHeapAgent.cpp:
(Inspector::SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask):
(Inspector::SendGarbageCollectionEventsTask::addGarbageCollection):
(Inspector::SendGarbageCollectionEventsTask::reset):
(Inspector::SendGarbageCollectionEventsTask::timerFired):
Added. This holds onto GarbageCollection objects that need to be sent asynchronously.
It uses the RunLoop variant of Timer and can queue multiple pending objects to be sent.
(Inspector::InspectorHeapAgent::InspectorHeapAgent):
(Inspector::InspectorHeapAgent::~InspectorHeapAgent):
(Inspector::InspectorHeapAgent::disable):
Reset the task when disabling or tearing down the agent so the timer doesn't fire after destruction.
(Inspector::InspectorHeapAgent::didGarbageCollect):
Send the object to the task to be dispatched asynchronously.
* inspector/agents/InspectorHeapAgent.h:
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (202442 => 202443)
--- trunk/Source/_javascript_Core/ChangeLog 2016-06-24 20:18:46 UTC (rev 202442)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-06-24 20:30:04 UTC (rev 202443)
@@ -1,3 +1,32 @@
+2016-06-24 Brian Burg <[email protected]>
+
+ Web Inspector: CRASH in backend at Inspector::HeapFrontendDispatcher::garbageCollected + 552 when closing frontend/inspected page
+ https://bugs.webkit.org/show_bug.cgi?id=159075
+ <rdar://problem/26094341>
+
+ Reviewed by Joseph Pecoraro.
+
+ Move the asynchronous work to a task class that can be cancelled when the
+ heap agent is reset, disabled or destroyed.
+
+ * inspector/agents/InspectorHeapAgent.cpp:
+ (Inspector::SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask):
+ (Inspector::SendGarbageCollectionEventsTask::addGarbageCollection):
+ (Inspector::SendGarbageCollectionEventsTask::reset):
+ (Inspector::SendGarbageCollectionEventsTask::timerFired):
+ Added. This holds onto GarbageCollection objects that need to be sent asynchronously.
+ It uses the RunLoop variant of Timer and can queue multiple pending objects to be sent.
+
+ (Inspector::InspectorHeapAgent::InspectorHeapAgent):
+ (Inspector::InspectorHeapAgent::~InspectorHeapAgent):
+ (Inspector::InspectorHeapAgent::disable):
+ Reset the task when disabling or tearing down the agent so the timer doesn't fire after destruction.
+
+ (Inspector::InspectorHeapAgent::didGarbageCollect):
+ Send the object to the task to be dispatched asynchronously.
+
+ * inspector/agents/InspectorHeapAgent.h:
+
2016-06-24 Commit Queue <[email protected]>
Unreviewed, rolling out r202413.
Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.cpp (202442 => 202443)
--- trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.cpp 2016-06-24 20:18:46 UTC (rev 202442)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.cpp 2016-06-24 20:30:04 UTC (rev 202443)
@@ -39,6 +39,48 @@
namespace Inspector {
+class SendGarbageCollectionEventsTask {
+public:
+ SendGarbageCollectionEventsTask(HeapFrontendDispatcher&);
+ void addGarbageCollection(RefPtr<Inspector::Protocol::Heap::GarbageCollection>&&);
+ void reset();
+private:
+ void timerFired();
+
+ HeapFrontendDispatcher& m_frontendDispatcher;
+ Vector<RefPtr<Inspector::Protocol::Heap::GarbageCollection>> m_garbageCollections;
+ RunLoop::Timer<SendGarbageCollectionEventsTask> m_timer;
+};
+
+SendGarbageCollectionEventsTask::SendGarbageCollectionEventsTask(HeapFrontendDispatcher& frontendDispatcher)
+ : m_frontendDispatcher(frontendDispatcher)
+ , m_timer(RunLoop::current(), this, &SendGarbageCollectionEventsTask::timerFired)
+{
+}
+
+void SendGarbageCollectionEventsTask::addGarbageCollection(RefPtr<Inspector::Protocol::Heap::GarbageCollection>&& garbageCollection)
+{
+ m_garbageCollections.append(WTFMove(garbageCollection));
+
+ if (!m_timer.isActive())
+ m_timer.startOneShot(0);
+}
+
+void SendGarbageCollectionEventsTask::reset()
+{
+ m_timer.stop();
+ m_garbageCollections.clear();
+}
+
+void SendGarbageCollectionEventsTask::timerFired()
+{
+ // The timer is stopped on agent destruction, so this method will never be called after agent has been destroyed.
+ for (auto& event : m_garbageCollections)
+ m_frontendDispatcher.garbageCollected(event);
+
+ m_garbageCollections.clear();
+}
+
InspectorHeapAgent::InspectorHeapAgent(AgentContext& context)
: InspectorAgentBase(ASCIILiteral("Heap"))
, m_injectedScriptManager(context.injectedScriptManager)
@@ -45,11 +87,13 @@
, m_frontendDispatcher(std::make_unique<HeapFrontendDispatcher>(context.frontendRouter))
, m_backendDispatcher(HeapBackendDispatcher::create(context.backendDispatcher, this))
, m_environment(context.environment)
+ , m_sendGarbageCollectionEventsTask(std::make_unique<SendGarbageCollectionEventsTask>(*m_frontendDispatcher))
{
}
InspectorHeapAgent::~InspectorHeapAgent()
{
+ m_sendGarbageCollectionEventsTask->reset();
}
void InspectorHeapAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
@@ -81,6 +125,7 @@
m_enabled = false;
m_environment.vm().heap.removeObserver(this);
+ m_sendGarbageCollectionEventsTask->reset();
clearHeapSnapshots();
}
@@ -276,9 +321,6 @@
// FIXME: Include number of bytes freed by collection.
- double startTime = m_gcStartTime;
- double endTime = m_environment.executionStopwatch()->elapsedTime();
-
// Dispatch the event asynchronously because this method may be
// called between collection and sweeping and we don't want to
// create unexpected _javascript_ allocations that the Sweeper does
@@ -286,16 +328,12 @@
// with WebKitLegacy's in process inspector which shares the same
// VM as the inspected page.
- RunLoop::current().dispatch([this, startTime, endTime, operation]() {
- auto collection = Inspector::Protocol::Heap::GarbageCollection::create()
- .setType(protocolTypeForHeapOperation(operation))
- .setStartTime(startTime)
- .setEndTime(endTime)
- .release();
+ m_sendGarbageCollectionEventsTask->addGarbageCollection(Inspector::Protocol::Heap::GarbageCollection::create()
+ .setType(protocolTypeForHeapOperation(operation))
+ .setStartTime(m_gcStartTime)
+ .setEndTime(m_environment.executionStopwatch()->elapsedTime())
+ .release());
- m_frontendDispatcher->garbageCollected(WTFMove(collection));
- });
-
m_gcStartTime = NAN;
}
Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.h (202442 => 202443)
--- trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.h 2016-06-24 20:18:46 UTC (rev 202442)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorHeapAgent.h 2016-06-24 20:30:04 UTC (rev 202443)
@@ -37,6 +37,7 @@
namespace Inspector {
class InjectedScriptManager;
+class SendGarbageCollectionEventsTask;
typedef String ErrorString;
class JS_EXPORT_PRIVATE InspectorHeapAgent : public InspectorAgentBase, public HeapBackendDispatcherHandler, public JSC::HeapObserver {
@@ -73,6 +74,8 @@
RefPtr<HeapBackendDispatcher> m_backendDispatcher;
InspectorEnvironment& m_environment;
+ std::unique_ptr<SendGarbageCollectionEventsTask> m_sendGarbageCollectionEventsTask;
+
bool m_enabled { false };
bool m_tracking { false };
double m_gcStartTime { NAN };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes