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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptWrappableHeapTracer.cpp

Issue 1876383003: Introduce infrastructure for tracing ScriptWrappables. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert to traceActiveScriptWrappables - C++ is happier Created 4 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "bindings/core/v8/ScriptWrappableHeapTracer.h"
6
7 #include "bindings/core/v8/ActiveScriptWrappable.h"
8 #include "bindings/core/v8/DOMDataStore.h"
9 #include "bindings/core/v8/ScriptWrappable.h"
10 #include "bindings/core/v8/ScriptWrappableVisitor.h"
11 #include "bindings/core/v8/WrapperTypeInfo.h"
12 #include "platform/heap/HeapPage.h"
13
14 namespace blink {
15
16 ScriptWrappableHeapTracer::~ScriptWrappableHeapTracer()
17 {
18 }
19
20 void ScriptWrappableHeapTracer::TraceRoots(v8::Isolate* isolate)
21 {
22 m_tracingInProgress = true;
23 ScriptWrappableVisitor visitor(isolate, this);
24 ActiveScriptWrappable::traceActiveScriptWrappables(&visitor);
25 }
26
27 void ScriptWrappableHeapTracer::AddHeaderToUnmark(HeapObjectHeader* header)
28 {
29 m_headersToUnmark.push_back(header);
30 }
31
32 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
33 {
34 for (auto header : m_headersToUnmark)
35 header->unmarkWrappable();
36
37 m_headersToUnmark.clear();
38 m_tracingInProgress = false;
39 }
40
41 void ScriptWrappableHeapTracer::TraceWrappableFrom(v8::Isolate* isolate, const s td::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.
42 {
43 ASSERT(m_tracingInProgress);
44 for (auto pair : internalFieldsOfPotentialWrappers) {
45 TraceWrappableFrom(isolate, pair);
46 }
47 }
48
49
50 void ScriptWrappableHeapTracer::TraceWrappableFrom(v8::Isolate* isolate, std::pa ir<void*, void*> internalFields)
51 {
52 if (!internalFields.first)
53 return;
54 if (reinterpret_cast<intptr_t>(internalFields.first) % 2 == 1)
55 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.
56 if (reinterpret_cast<WrapperTypeInfo*>(internalFields.first)->ginEmbedder
57 != gin::GinEmbedder::kEmbedderBlink)
58 return;
59
60 ScriptWrappable* scriptWrappable = reinterpret_cast<ScriptWrappable*>(
61 internalFields.second);
62 uint16_t classId = scriptWrappable->wrapperTypeInfo()->wrapperClassId;
63 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
64 && classId != WrapperTypeInfo::ObjectClassId) {
65 ASSERT_NOT_REACHED();
66 return;
67 }
68
69 ScriptWrappableVisitor visitor(isolate, this);
70 visitor.traceWrappers(scriptWrappable);
71 }
72
73 void ScriptWrappableHeapTracer::TraceWrappableFrom(v8::Isolate* isolate, v8::Per sistent<v8::Object>* handle)
74 {
75 ScriptWrappable* scriptWrappable = toScriptWrappable(*handle);
76 uint16_t classId = scriptWrappable->wrapperTypeInfo()->wrapperClassId;
77 if (classId != WrapperTypeInfo::NodeClassId
78 && classId != WrapperTypeInfo::ObjectClassId) {
79 ASSERT_NOT_REACHED();
80 return;
81 }
82
83 ScriptWrappableVisitor visitor(isolate, this);
84 visitor.traceWrappers(scriptWrappable);
85 }
86
87 void ScriptWrappableHeapTracer::markWrapper(const v8::Persistent<v8::Object>& ha ndle, v8::Isolate* isolate)
88 {
89 handle.RegisterExternalReference(isolate);
90 }
91
92 void ScriptWrappableHeapTracer::markWrapper(const ScriptWrappable* scriptWrappab le, v8::Isolate* isolate)
haraken 2016/04/18 04:35:42 markWrapper => markWrappersInAllWorlds ?
Marcel Hlopko 2016/04/18 11:45:35 Done.
93 {
94 ExternalReferenceRegisteringVisitor visitor(
95 const_cast<ScriptWrappable*>(scriptWrappable),
96 isolate);
97 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.
98 }
99
100 void ScriptWrappableHeapTracer::ExternalReferenceRegisteringVisitor::visit(DOMWr apperWorld& world)
101 {
102 DOMDataStore& dataStore = world.domDataStore();
103 if (dataStore.containsWrapper(m_scriptWrappable))
104 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
105 }
106
107 }
108
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698