Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Deterministic HeapHashSet iteration draft #584

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions base/record_replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ struct ReplayRefPointerIdHash : ReplayPointerIdHash<T> {
static bool Equal(const scoped_refptr<T>& a, T* b) { return a == b; }
};

class RecordReplayIdMixin {
public:
RecordReplayIdMixin()
: record_replay_id_(NewIdAnyThread("RecordReplayIdMixin")) {}

int RecordReplayId() const { return record_replay_id_; }

private:
int record_replay_id_ = 0;
};

// For taking ordered locks when events might be disallowed. Passes through
// events during the acquire to avoid generating a warning.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/types/pass_key.h"
#include "components/shared_highlighting/core/common/shared_highlighting_metrics.h"
#include "third_party/blink/public/mojom/annotation/annotation.mojom-blink.h"
#include "third_party/blink/renderer/core/annotation/annotation_agent_impl.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/fragment_directive/text_fragment_selector_generator.h"
Expand All @@ -20,7 +21,7 @@
namespace blink {

class AnnotationAgentContainerImplTest;
class AnnotationAgentImpl;
// class AnnotationAgentImpl;
class AnnotationSelector;
class LocalFrame;
class AnnotationAgentGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_ANNOTATION_ANNOTATION_AGENT_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANNOTATION_ANNOTATION_AGENT_IMPL_H_

#include "base/record_replay.h"
#include "base/types/pass_key.h"
#include "third_party/blink/public/mojom/annotation/annotation.mojom-blink.h"
#include "third_party/blink/renderer/core/core_export.h"
Expand Down Expand Up @@ -47,7 +48,8 @@ class RangeInFlatTree;
// closes the connection, the AnnotationAgentImpl will be removed)
class CORE_EXPORT AnnotationAgentImpl final
: public GarbageCollected<AnnotationAgentImpl>,
public mojom::blink::AnnotationAgent {
public mojom::blink::AnnotationAgent,
public recordreplay::RecordReplayIdMixin {
public:
using PassKey = base::PassKey<AnnotationAgentImpl>;

Expand Down
4 changes: 3 additions & 1 deletion third_party/blink/renderer/core/clipboard/data_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_CLIPBOARD_DATA_OBJECT_H_

#include "base/memory/scoped_refptr.h"
#include "base/record_replay.h"
#include "third_party/blink/renderer/core/clipboard/data_object_item.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
Expand All @@ -56,7 +57,8 @@ enum class PasteMode;
class CORE_EXPORT DataObject : public GarbageCollected<DataObject>,
public Supplementable<DataObject> {
public:
struct CORE_EXPORT Observer : public GarbageCollectedMixin {
struct CORE_EXPORT Observer : public GarbageCollectedMixin,
public recordreplay::RecordReplayIdMixin {
// Called whenever |item_list_| is modified. Note it can be called multiple
// times for a single mutation. For example, DataObject::SetData() calls
// both ClearData() and Add(), each of which can call this method.
Expand Down
7 changes: 5 additions & 2 deletions third_party/blink/renderer/core/css/counter_style_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/css/style_rule_counter_style.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"

namespace blink {
Expand Down Expand Up @@ -275,7 +276,9 @@ void CounterStyleMap::MarkDirtyCounterStyles(
// static
void CounterStyleMap::MarkAllDirtyCounterStyles(
Document& document,
const HeapHashSet<Member<TreeScope>>& active_tree_scopes) {
const HeapHashSet<Member<TreeScope>,
WTF::MemberHashRecordReplayId<TreeScope>>&
active_tree_scopes) {
// Traverse all CounterStyle objects in the document to mark dirtiness.
// We assume that there are not too many CounterStyle objects, so this won't
// be a performance bottleneck.
Expand All @@ -298,7 +301,7 @@ void CounterStyleMap::MarkAllDirtyCounterStyles(
// static
void CounterStyleMap::ResolveAllReferences(
Document& document,
const HeapHashSet<Member<TreeScope>>& active_tree_scopes) {
const HeapHashSet<Member<TreeScope>, WTF::MemberHashRecordReplayId<TreeScope>>& active_tree_scopes) {
// Traverse all counter style maps to find and update CounterStyles that are
// dirty or have unresolved references. We assume there are not too many
// CounterStyles, so that this won't be a performance bottleneck.
Expand Down
13 changes: 9 additions & 4 deletions third_party/blink/renderer/core/css/counter_style_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/css/counter_style.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_map.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_hash.h"

Expand All @@ -33,12 +34,16 @@ class CORE_EXPORT CounterStyleMap : public GarbageCollected<CounterStyleMap> {
void AddCounterStyles(const RuleSet&);

void ResolveReferences(HeapHashSet<Member<CounterStyleMap>>& resolved_maps);
static void ResolveAllReferences(Document&,
const HeapHashSet<Member<TreeScope>>&);
static void ResolveAllReferences(
Document&,
const HeapHashSet<Member<TreeScope>,
WTF::MemberHashRecordReplayId<TreeScope>>&);

void MarkDirtyCounterStyles(HeapHashSet<Member<CounterStyle>>& visited);
static void MarkAllDirtyCounterStyles(Document&,
const HeapHashSet<Member<TreeScope>>&);
static void MarkAllDirtyCounterStyles(
Document&,
const HeapHashSet<Member<TreeScope>,
WTF::MemberHashRecordReplayId<TreeScope>>&);

void Dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "base/callback.h"
#include "base/containers/lru_cache.h"
#include "base/record_replay.h"
#include "third_party/blink/renderer/platform/fonts/font_cache_key.h"
#include "third_party/blink/renderer/platform/fonts/font_selection_types.h"
#include "third_party/blink/renderer/platform/fonts/segmented_font_data.h"
Expand Down Expand Up @@ -87,7 +88,8 @@ class FontFaceList : public GarbageCollected<FontFaceList> {
};

class CSSSegmentedFontFace final
: public GarbageCollected<CSSSegmentedFontFace> {
: public GarbageCollected<CSSSegmentedFontFace>,
public recordreplay::RecordReplayIdMixin {
public:
static CSSSegmentedFontFace* Create(FontSelectionCapabilities);

Expand Down
16 changes: 10 additions & 6 deletions third_party/blink/renderer/core/css/style_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_map.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/loader/fetch/render_blocking_behavior.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
Expand Down Expand Up @@ -449,10 +450,10 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,
Element& removed_element,
Element& after_element);
void ScheduleNthPseudoInvalidations(ContainerNode&);
void ScheduleInvalidationsForRuleSets(TreeScope&,
const HeapHashSet<Member<RuleSet>>&,
InvalidationScope =
kInvalidateCurrentScope);
void ScheduleInvalidationsForRuleSets(
TreeScope&,
const HeapHashSet<Member<RuleSet>>&,
InvalidationScope = kInvalidateCurrentScope);
void ScheduleCustomElementInvalidations(HashSet<AtomicString> tag_names);
void ScheduleInvalidationsForHasPseudoAffectedByInsertion(
Element* parent,
Expand Down Expand Up @@ -647,7 +648,9 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,

Document& GetDocument() const { return *document_; }

typedef HeapHashSet<Member<TreeScope>> UnorderedTreeScopeSet;
typedef HeapHashSet<Member<TreeScope>,
WTF::MemberHashRecordReplayId<TreeScope>>
UnorderedTreeScopeSet;

bool MediaQueryAffectingValueChanged(const ActiveStyleSheetVector&,
MediaValueChange);
Expand Down Expand Up @@ -886,7 +889,8 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,

Member<CSSFontSelector> font_selector_;

HeapHashMap<AtomicString, WeakMember<StyleSheetContents>> text_to_sheet_cache_;
HeapHashMap<AtomicString, WeakMember<StyleSheetContents>>
text_to_sheet_cache_;
HeapHashMap<WeakMember<StyleSheetContents>, AtomicString>
sheet_to_text_cache_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <utility>

#include "base/record_replay.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/style_recalc_change.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
Expand Down
6 changes: 5 additions & 1 deletion third_party/blink/renderer/core/dom/document_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"

// For RecordReplayId
#include "third_party/blink/renderer/core/dom/document_parser_client.h"

namespace blink {

class Document;
class DocumentParserClient;
// class DocumentParserClient;
class ScriptableDocumentParser;
class TextResourceDecoder;

Expand Down
4 changes: 3 additions & 1 deletion third_party/blink/renderer/core/dom/document_parser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_DOM_DOCUMENT_PARSER_CLIENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_DOM_DOCUMENT_PARSER_CLIENT_H_

#include "base/record_replay.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"

namespace blink {

class DocumentParserClient : public GarbageCollectedMixin {
class DocumentParserClient : public GarbageCollectedMixin,
public recordreplay::RecordReplayIdMixin {
public:
// This callback is called when all data pushed to parser has been consumed.
virtual void NotifyParserStopped() = 0;
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/core/dom/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class CORE_EXPORT Element : public ContainerNode, public Animatable {
DEFINE_WRAPPERTYPEINFO();

public:
using ScriptWrappable::RecordReplayId;

Element(const QualifiedName& tag_name,
Document*,
ConstructionType = kCreateElement);
Expand Down
4 changes: 3 additions & 1 deletion third_party/blink/renderer/core/dom/id_target_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_DOM_ID_TARGET_OBSERVER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_DOM_ID_TARGET_OBSERVER_H_

#include "base/record_replay.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
Expand All @@ -34,7 +35,8 @@ namespace blink {

class IdTargetObserverRegistry;

class IdTargetObserver : public GarbageCollected<IdTargetObserver> {
class IdTargetObserver : public GarbageCollected<IdTargetObserver>,
public recordreplay::RecordReplayIdMixin {
public:
virtual ~IdTargetObserver();
virtual void Trace(Visitor*) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"

// For RecordReplayId
#include "third_party/blink/renderer/core/dom/id_target_observer.h"

namespace blink {

class IdTargetObserver;
// class IdTargetObserver;

class CORE_EXPORT IdTargetObserverRegistry final
: public GarbageCollected<IdTargetObserverRegistry> {
Expand Down
10 changes: 8 additions & 2 deletions third_party/blink/renderer/core/dom/mutation_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/heap/prefinalizer.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

Expand All @@ -58,9 +59,12 @@ class Node;
class ScriptState;
class V8MutationCallback;

using MutationObserverSet = HeapHashSet<Member<MutationObserver>>;
using MutationObserverSet =
HeapHashSet<Member<MutationObserver>,
WTF::MemberHashRecordReplayId<MutationObserver>>;
using MutationObserverRegistrationSet =
HeapHashSet<WeakMember<MutationObserverRegistration>>;
HeapHashSet<WeakMember<MutationObserverRegistration>,
WTF::MemberHashRecordReplayId<MutationObserverRegistration>>;
using MutationObserverVector = HeapVector<Member<MutationObserver>>;
using MutationRecordVector = HeapVector<Member<MutationRecord>>;

Expand All @@ -73,6 +77,8 @@ class CORE_EXPORT MutationObserver final
USING_PRE_FINALIZER(MutationObserver, CancelInspectorAsyncTasks);

public:
using ScriptWrappable::RecordReplayId;

enum ObservationFlags { kSubtree = 1 << 3, kAttributeFilter = 1 << 4 };

enum DeliveryFlags {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_DOM_MUTATION_OBSERVER_REGISTRATION_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_DOM_MUTATION_OBSERVER_REGISTRATION_H_

#include "base/record_replay.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/mutation_observer.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string_hash.h"
Expand All @@ -46,7 +48,8 @@ class QualifiedName;

class CORE_EXPORT MutationObserverRegistration final
: public GarbageCollected<MutationObserverRegistration>,
public NameClient {
public NameClient,
public recordreplay::RecordReplayIdMixin {
public:
MutationObserverRegistration(MutationObserver&,
Node*,
Expand Down Expand Up @@ -91,7 +94,8 @@ class CORE_EXPORT MutationObserverRegistration final
Member<MutationObserver> observer_;
WeakMember<Node> registration_node_;
Member<Node> registration_node_keep_alive_;
typedef HeapHashSet<Member<Node>> NodeHashSet;
typedef HeapHashSet<Member<Node>, WTF::MemberHashRecordReplayId<Node>>
NodeHashSet;
Member<NodeHashSet> transient_registration_nodes_;

MutationObserverOptions options_;
Expand Down
19 changes: 12 additions & 7 deletions third_party/blink/renderer/core/dom/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_dom_wrapper.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/instrumentation/instance_counters.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/traced_value.h"
Expand All @@ -141,7 +142,9 @@
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace v8 { extern std::string RecordReplayGetScriptedCaller(); }
namespace v8 {
extern std::string RecordReplayGetScriptedCaller();
}

namespace blink {

Expand Down Expand Up @@ -1598,7 +1601,7 @@ void Node::AttachLayoutTree(AttachContext& context) {

void Node::DetachLayoutTree(bool performing_reattach) {
recordreplay::Assert("[RUN-1219-1694] Node::DetachLayoutTree %d",
this->RecordReplayId());
this->RecordReplayId());
DCHECK(GetDocument().Lifecycle().StateAllowsDetach() ||
GetDocument().GetStyleEngine().InContainerQueryStyleRecalc());
DCHECK(!performing_reattach ||
Expand Down Expand Up @@ -2045,9 +2048,11 @@ void Node::setTextContent(const String& text_arg) {
// layout behavior diverges afterwards. See also Text::Create.
if (recordreplay::IsRecordingOrReplaying("values")) {
std::string contents = text.Utf8();
size_t recordedLength = recordreplay::RecordReplayValue("Node::setTextContent length", contents.length());
size_t recordedLength = recordreplay::RecordReplayValue(
"Node::setTextContent length", contents.length());
contents.resize(recordedLength, ' ');
recordreplay::RecordReplayBytes("Node::setTextContent string", &contents[0], recordedLength);
recordreplay::RecordReplayBytes("Node::setTextContent string", &contents[0],
recordedLength);
text = String::FromUTF8(&contents[0], recordedLength);

// https://linear.app/replay/issue/RUN-809
Expand Down Expand Up @@ -2767,7 +2772,8 @@ Node::MutationObserverRegistry() {
return &data->Registry();
}

const HeapHashSet<Member<MutationObserverRegistration>>*
const HeapHashSet<Member<MutationObserverRegistration>,
WTF::MemberHashRecordReplayId<MutationObserverRegistration>>*
Node::TransientMutationObserverRegistry() {
if (!HasRareData())
return nullptr;
Expand Down Expand Up @@ -2870,8 +2876,7 @@ void Node::RegisterTransientMutationObserver(

void Node::UnregisterTransientMutationObserver(
MutationObserverRegistration* registration) {
const HeapHashSet<Member<MutationObserverRegistration>>* transient_registry =
TransientMutationObserverRegistry();
const auto* transient_registry = TransientMutationObserverRegistry();
DCHECK(transient_registry);
if (!transient_registry)
return;
Expand Down
Loading