Skip to content

Commit

Permalink
hashtable: make it ordered
Browse files Browse the repository at this point in the history
  • Loading branch information
oridb committed May 4, 2023
1 parent 09de96c commit e5de1a7
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 153 deletions.
6 changes: 3 additions & 3 deletions base/allocator/partition_allocator/partition_alloc_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void PartitionAllocHooks::SetObserverHooks(AllocationObserverHook* alloc_hook,
void PartitionAllocHooks::SetOverrideHooks(AllocationOverrideHook* alloc_hook,
FreeOverrideHook* free_hook,
ReallocOverrideHook realloc_hook) {
if (recordreplay::IsRecordingOrReplaying()) {
//if (recordreplay::IsRecordingOrReplaying()) {
// Always use the default allocators when recording/replaying.
return;
}
// return;
//}

internal::ScopedGuard guard(GetHooksLock());

Expand Down
6 changes: 3 additions & 3 deletions base/allocator/partition_allocator/shim/allocator_shim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ ALWAYS_INLINE void ShimAlignedFree(void* address, void* context) {
#include "base/allocator/partition_allocator/shim/allocator_shim_override_glibc_weak_symbols.h"
#endif

static inline bool MaybeRecordingOrReplaying() {
return true;
}
//static inline bool MaybeRecordingOrReplaying() {
// return true;
//}

#if BUILDFLAG(IS_APPLE)
namespace allocator_shim {
Expand Down
4 changes: 2 additions & 2 deletions base/functional/bind_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ struct CallbackCancellationTraits {
static constexpr bool is_cancellable = false;
};

extern uintptr_t CallbackRecordReplayValue(const char* why, uintptr_t value);
//extern uintptr_t CallbackRecordReplayValue(const char* why, uintptr_t value);

// Specialization for method bound to weak pointer receiver.
template <typename Functor, typename... BoundArgs>
Expand All @@ -1600,7 +1600,7 @@ struct CallbackCancellationTraits<
// Weak pointers can be cleared non-deterministically when recording/replaying,
// so record/replay whether they are present so that callers checking the status
// like TaskQueueImpl behave consistently.
return CallbackRecordReplayValue("WeakMethodIsCancelled", !receiver);
return 0; //CallbackRecordReplayValue("WeakMethodIsCancelled", !receiver);
}

template <typename Receiver, typename... Args>
Expand Down
2 changes: 1 addition & 1 deletion base/process/process_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void Process::TerminateCurrentProcessImmediately(int exit_code) {
#if BUILDFLAG(CLANG_PROFILING)
WriteClangProfilingProfile();
#endif
V8RecordReplayFinishRecording();
//V8RecordReplayFinishRecording();
_exit(exit_code);
}

Expand Down
142 changes: 61 additions & 81 deletions base/record_replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,20 @@ ForEachV8APIVoid(DefineFunctionVoid)
#endif // !BUILD_FLAG(IS_WIN)

bool IsRecordingOrReplaying(const char* feature) {
return V8IsRecordingOrReplaying(feature);
return false; //V8IsRecordingOrReplaying(feature);
}

bool IsRecording() {
return V8IsRecording();
return false; //V8IsRecording();
}

bool IsReplaying() {
return V8IsReplaying();
return false; //V8IsReplaying();
}

char* GetRecordingId() {
return V8GetRecordingId();
static char ret[1] = "";
return ret; //V8GetRecordingId();
}

bool HadMismatch() {
Expand All @@ -184,7 +185,7 @@ void Assert(const char* format, ...) {
#ifndef NACL_TC_REV
va_list ap;
va_start(ap, format);
V8RecordReplayAssertVA(format, ap);
//V8RecordReplayAssertVA(format, ap);
va_end(ap);
#endif
}
Expand All @@ -193,7 +194,7 @@ void Diagnostic(const char* format, ...) {
#ifndef NACL_TC_REV
va_list ap;
va_start(ap, format);
V8RecordReplayDiagnosticVA(format, ap);
//V8RecordReplayDiagnosticVA(format, ap);
va_end(ap);
#endif
}
Expand All @@ -202,151 +203,151 @@ void Warning(const char* format, ...) {
#ifndef NACL_TC_REV
va_list ap;
va_start(ap, format);
V8RecordReplayWarning(format, ap);
//V8RecordReplayWarning(format, ap);
va_end(ap);
#endif
}

void AssertBytes(const char* why, const void* buf, size_t size) {
V8RecordReplayAssertBytes(why, buf, size);
//V8RecordReplayAssertBytes(why, buf, size);
}

void Print(const char* format, ...) {
#ifndef NACL_TC_REV
va_list ap;
va_start(ap, format);
V8RecordReplayPrintVA(format, ap);
//V8RecordReplayPrintVA(format, ap);
va_end(ap);
#endif
}

uintptr_t RecordReplayValue(const char* why, uintptr_t v) {
return V8RecordReplayValue(why, v);
return 0; //V8RecordReplayValue(why, v);
}

void RecordReplayBytes(const char* why, void* buf, size_t size) {
V8RecordReplayBytes(why, buf, size);
//V8RecordReplayBytes(why, buf, size);
}

int CreateOrderedLock(const char* name) {
return (int)V8RecordReplayCreateOrderedLock(name);
return 0; //(int)V8RecordReplayCreateOrderedLock(name);
}

void OrderedLock(int lock) {
V8RecordReplayOrderedLock(lock);
//V8RecordReplayOrderedLock(lock);
}

void OrderedUnlock(int lock) {
V8RecordReplayOrderedUnlock(lock);
//V8RecordReplayOrderedUnlock(lock);
}

void NewCheckpoint() {
V8RecordReplayNewCheckpoint();
//V8RecordReplayNewCheckpoint();
}

uint64_t NewBookmark() {
return V8RecordReplayNewBookmark();
return 0; //V8RecordReplayNewBookmark();
}

void OnAnnotation(const char* kind, const char* contents) {
V8RecordReplayOnAnnotation(kind, contents);
//V8RecordReplayOnAnnotation(kind, contents);
}

void OnNetworkRequest(const char* id, const char* kind, uint64_t bookmark) {
V8RecordReplayOnNetworkRequest(id, kind, bookmark);
//V8RecordReplayOnNetworkRequest(id, kind, bookmark);
}

void OnNetworkRequestEvent(const char* id) {
V8RecordReplayOnNetworkRequestEvent(id);
//V8RecordReplayOnNetworkRequestEvent(id);
}

void OnNetworkStreamStart(const char* id, const char* kind, const char* parentId) {
V8RecordReplayOnNetworkStreamStart(id, kind, parentId);
//V8RecordReplayOnNetworkStreamStart(id, kind, parentId);
}

void OnNetworkStreamData(const char* id, size_t offset, size_t length, uint64_t bookmark) {
V8RecordReplayOnNetworkStreamData(id, offset, length, bookmark);
//V8RecordReplayOnNetworkStreamData(id, offset, length, bookmark);
}

void OnNetworkStreamEnd(const char* id, size_t length) {
V8RecordReplayOnNetworkStreamEnd(id, length);
//V8RecordReplayOnNetworkStreamEnd(id, length);
}

bool AreEventsDisallowed() {
return V8RecordReplayAreEventsDisallowed();
return false; //V8RecordReplayAreEventsDisallowed();
}

void BeginDisallowEvents() {
V8RecordReplayBeginDisallowEvents();
//V8RecordReplayBeginDisallowEvents();
}

void BeginDisallowEventsWithLabel(const char* label) {
V8RecordReplayBeginDisallowEventsWithLabel(label);
//iV8RecordReplayBeginDisallowEventsWithLabel(label);
}

void EndDisallowEvents() {
V8RecordReplayEndDisallowEvents();
//V8RecordReplayEndDisallowEvents();
}

bool AreEventsPassedThrough() {
return V8RecordReplayAreEventsPassedThrough();
return 0; //V8RecordReplayAreEventsPassedThrough();
}

void BeginPassThroughEvents() {
V8RecordReplayBeginPassThroughEvents();
//V8RecordReplayBeginPassThroughEvents();
}

void EndPassThroughEvents() {
V8RecordReplayEndPassThroughEvents();
//V8RecordReplayEndPassThroughEvents();
}

bool FeatureEnabled(const char* feature) {
return V8RecordReplayFeatureEnabled(feature);
return false;//V8RecordReplayFeatureEnabled(feature);
}

void BrowserEvent(const char* name, const base::DictionaryValue& info) {
std::string json;
base::JSONWriter::Write(info, &json);
V8RecordReplayBrowserEvent(name, json.c_str());
//std::string json;
//base::JSONWriter::Write(info, &json);
//V8RecordReplayBrowserEvent(name, json.c_str());
}

bool HasDivergedFromRecording() {
return V8RecordReplayHasDivergedFromRecording();
return false;//V8RecordReplayHasDivergedFromRecording();
}

bool AllowSideEffects() {
return V8RecordReplayAllowSideEffects();
return false; //V8RecordReplayAllowSideEffects();
}

void RegisterPointer(const char* name, const void* ptr) {
V8RecordReplayRegisterPointer(name, ptr);
//V8RecordReplayRegisterPointer(name, ptr);
}

void UnregisterPointer(const void* ptr) {
V8RecordReplayUnregisterPointer(ptr);
//V8RecordReplayUnregisterPointer(ptr);
}

int PointerId(const void* ptr) {
return V8RecordReplayPointerId(ptr);
return 0; //V8RecordReplayPointerId(ptr);
}

void* IdPointer(int id) {
return V8RecordReplayIdPointer(id);
return nullptr; //V8RecordReplayIdPointer(id);
}

void OnEvent(const char* aEvent, bool aBefore) {
V8RecordReplayOnEvent(aEvent, aBefore);
//V8RecordReplayOnEvent(aEvent, aBefore);
}
void OnMouseEvent(const char* kind,
size_t clientX,
size_t clientY) {
V8RecordReplayOnMouseEvent(kind, clientX, clientY);
//V8RecordReplayOnMouseEvent(kind, clientX, clientY);
}
void OnKeyEvent(const char* kind, const char* key) {
V8RecordReplayOnKeyEvent(kind, key);
//V8RecordReplayOnKeyEvent(kind, key);
}
void OnNavigationEvent(const char* kind, const char* url) {
V8RecordReplayOnNavigationEvent(kind, url);
//V8RecordReplayOnNavigationEvent(kind, url);
}

AutoLockMaybeEventsDisallowed::AutoLockMaybeEventsDisallowed(
Expand Down Expand Up @@ -378,50 +379,29 @@ AutoUnlockMaybeEventsDisallowed::~AutoUnlockMaybeEventsDisallowed() {
}

bool IsMainThread() {
return V8IsMainThread();
}

static int gNextMainThreadId = 1;

static bool CheckNewId(const char* name) {
if (!IsRecordingOrReplaying()) {
// Don't track anything.
return false;
}
if (HasDivergedFromRecording()) {
// Everything is allowed when explicitly diverged.
return true;
}
if (AreEventsDisallowed()) {
// IDs can be created when events are disallowed when our own scripts
// create URL objects. This would be nice to improve.
if (!IsInReplayCode()) {
Warning("NewId when not allowed %s", name);
}
return false;
}
Assert("NewId %s", name);
return true;
return false; //V8IsMainThread();
}

//static int gNextMainThreadId = 1;
int NewIdMainThread(const char* name) {
if (!CheckNewId(name)) {
return 0;
}
if (!V8IsMainThread()) {
fprintf(stderr, "NewIdMainThread not main thread: %s\n", name);
CHECK(V8IsMainThread());
}
return gNextMainThreadId++;
// if (IsRecordingOrReplaying()) {
// if (!V8IsMainThread()) {
// fprintf(stderr, "NewIdMainThread not main thread: %s\n", name);
// CHECK(V8IsMainThread());
// }
// Assert("NewId %s", name);
// return gNextMainThreadId++;
// }
return 0;
}

static std::atomic<int> gNextAnyThreadId{1};
//static std::atomic<int> gNextAnyThreadId{1};

int NewIdAnyThread(const char* name) {
if (!CheckNewId(name)) {
//if (!CheckNewId(name)) {
return 0;
}
return (int)RecordReplayValue("NewId", (uintptr_t)gNextAnyThreadId++);
//}
//return (int)RecordReplayValue("NewId", (uintptr_t)gNextAnyThreadId++);
}

bool IsInReplayCode() {
Expand All @@ -441,15 +421,15 @@ void RecordReplayString(const char* why, std::string& str) {
}

void AddOrderedSRWLock(const char* name, void* lock) {
V8RecordReplayAddOrderedSRWLock(name, lock);
//V8RecordReplayAddOrderedSRWLock(name, lock);
}

void RemoveOrderedSRWLock(void* lock) {
V8RecordReplayRemoveOrderedSRWLock(lock);
}

void MaybeTerminate(void (*callback)(void*), void* data) {
V8RecordReplayMaybeTerminate(callback, data);
//V8RecordReplayMaybeTerminate(callback, data);
}

} // namespace recordreplay
4 changes: 2 additions & 2 deletions mojo/core/ports/port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Port::Port(uint64_t next_sequence_num_to_send,
peer_lost_unexpectedly(false),
lock_("Port.lock_") {
// Registering new ports is needed for sorting, see port_locker.cc
recordreplay::RegisterPointer("Port", this);
//recordreplay::RegisterPointer("Port", this);
}

Port::~Port() {
recordreplay::UnregisterPointer(this);
//recordreplay::UnregisterPointer(this);
}

bool Port::IsNextEvent(const NodeName& from_node, const Event& event) {
Expand Down
8 changes: 0 additions & 8 deletions mojo/core/ports/port_locker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ void UpdateTLS(PortLocker* old_locker, PortLocker* new_locker) {
} // namespace

static uintptr_t GetPortId(Port* port) {
// When recording/replaying the sorted order of ports need to be consistent,
// so we use the ID associated with the port via RegisterPointer for sorting.
if (recordreplay::IsRecordingOrReplaying("pointer-ids")) {
uintptr_t id = recordreplay::PointerId(port);
CHECK(id);
return id;
} else {
return (uintptr_t)port;
}
}

PortLocker::PortLocker(const PortRef** port_refs, size_t num_ports)
Expand Down
Loading

0 comments on commit e5de1a7

Please sign in to comment.