Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp |
| diff --git a/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp b/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f7d319c7ef937a27e16cb2cecc6937b45a36c6bf |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp |
| @@ -0,0 +1,108 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "bindings/core/v8/ScriptWrappableHeapTracer.h" |
| + |
| +#include "bindings/core/v8/ActiveScriptWrappable.h" |
| +#include "bindings/core/v8/DOMDataStore.h" |
| +#include "bindings/core/v8/ScriptWrappable.h" |
| +#include "bindings/core/v8/ScriptWrappableVisitor.h" |
| +#include "bindings/core/v8/WrapperTypeInfo.h" |
| +#include "platform/heap/HeapPage.h" |
| + |
| +namespace blink { |
| + |
| +ScriptWrappableHeapTracer::~ScriptWrappableHeapTracer() |
| +{ |
| +} |
| + |
| +void ScriptWrappableHeapTracer::TraceRoots(v8::Isolate* isolate) |
| +{ |
| + m_tracingInProgress = true; |
| + ScriptWrappableVisitor visitor(isolate, this); |
| + ActiveScriptWrappable::traceActiveScriptWrappables(&visitor); |
| +} |
| + |
| +void ScriptWrappableHeapTracer::AddHeaderToUnmark(HeapObjectHeader* header) |
| +{ |
| + m_headersToUnmark.push_back(header); |
| +} |
| + |
| +void ScriptWrappableHeapTracer::ClearTracingMarks(v8::Isolate* isolate) |
|
haraken
2016/04/18 04:35:42
TraceRoots => TracePrologue
ClearTracingMarks => T
Marcel Hlopko
2016/04/18 11:45:35
I like it, I uploaded cl for the v8 side, after la
|
| +{ |
| + for (auto header : m_headersToUnmark) |
| + header->unmarkWrappable(); |
| + |
| + m_headersToUnmark.clear(); |
| + m_tracingInProgress = false; |
| +} |
| + |
| +void ScriptWrappableHeapTracer::TraceWrappableFrom(v8::Isolate* isolate, const std::vector<std::pair<void*, void*>>& internalFieldsOfPotentialWrappers) |
|
haraken
2016/04/18 04:35:42
std::vector is not allowed in Blink.
Can we use a
Marcel Hlopko
2016/04/18 11:45:35
Leaving as is after the discussion.
|
| +{ |
| + ASSERT(m_tracingInProgress); |
| + for (auto pair : internalFieldsOfPotentialWrappers) { |
| + TraceWrappableFrom(isolate, pair); |
| + } |
| +} |
| + |
| + |
| +void ScriptWrappableHeapTracer::TraceWrappableFrom(v8::Isolate* isolate, std::pair<void*, void*> internalFields) |
| +{ |
| + if (!internalFields.first) |
| + return; |
| + if (reinterpret_cast<intptr_t>(internalFields.first) % 2 == 1) |
| + ASSERT_NOT_REACHED(); |
|
haraken
2016/04/18 04:35:42
Then we can encapsulate this mysterious check in t
Marcel Hlopko
2016/04/18 11:45:35
Agreed, moved.
|
| + if (reinterpret_cast<WrapperTypeInfo*>(internalFields.first)->ginEmbedder |
| + != gin::GinEmbedder::kEmbedderBlink) |
| + return; |
| + |
| + ScriptWrappable* scriptWrappable = reinterpret_cast<ScriptWrappable*>( |
| + internalFields.second); |
| + uint16_t classId = scriptWrappable->wrapperTypeInfo()->wrapperClassId; |
| + if (classId != WrapperTypeInfo::NodeClassId |
|
haraken
2016/04/18 04:35:41
Actually I want to ask V8 to pass in the class ID
Marcel Hlopko
2016/04/18 11:45:35
I'm afraid that getting class id from a wrapper is
|
| + && classId != WrapperTypeInfo::ObjectClassId) { |
| + ASSERT_NOT_REACHED(); |
| + return; |
| + } |
| + |
| + ScriptWrappableVisitor visitor(isolate, this); |
| + visitor.traceWrappers(scriptWrappable); |
| +} |
| + |
| +void ScriptWrappableHeapTracer::TraceWrappableFrom(v8::Isolate* isolate, v8::Persistent<v8::Object>* handle) |
| +{ |
| + ScriptWrappable* scriptWrappable = toScriptWrappable(*handle); |
| + uint16_t classId = scriptWrappable->wrapperTypeInfo()->wrapperClassId; |
| + if (classId != WrapperTypeInfo::NodeClassId |
| + && classId != WrapperTypeInfo::ObjectClassId) { |
| + ASSERT_NOT_REACHED(); |
| + return; |
| + } |
| + |
| + ScriptWrappableVisitor visitor(isolate, this); |
| + visitor.traceWrappers(scriptWrappable); |
| +} |
| + |
| +void ScriptWrappableHeapTracer::markWrapper(const v8::Persistent<v8::Object>& handle, v8::Isolate* isolate) |
| +{ |
| + handle.RegisterExternalReference(isolate); |
| +} |
| + |
| +void ScriptWrappableHeapTracer::markWrapper(const ScriptWrappable* scriptWrappable, v8::Isolate* isolate) |
|
haraken
2016/04/18 04:35:42
markWrapper => markWrappersInAllWorlds ?
Marcel Hlopko
2016/04/18 11:45:35
Done.
|
| +{ |
| + ExternalReferenceRegisteringVisitor visitor( |
| + const_cast<ScriptWrappable*>(scriptWrappable), |
| + isolate); |
| + DOMWrapperWorld::visitAllWorldsInMainThread(visitor); |
|
haraken
2016/04/18 04:35:42
visitAllWorldsInMainThread doesn't much make sense
Marcel Hlopko
2016/04/18 11:45:35
Agreed, updated the code accordingly.
|
| +} |
| + |
| +void ScriptWrappableHeapTracer::ExternalReferenceRegisteringVisitor::visit(DOMWrapperWorld& world) |
| +{ |
| + DOMDataStore& dataStore = world.domDataStore(); |
| + if (dataStore.containsWrapper(m_scriptWrappable)) |
| + dataStore.markWrapper(m_scriptWrappable, m_isolate); |
|
haraken
2016/04/18 04:35:41
And you can call this in DOMWrapperWorld::markWrap
Marcel Hlopko
2016/04/18 11:45:35
Fixed and TODO added. I worry about the performanc
|
| +} |
| + |
| +} |
| + |