Commit 694de0a7 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap: Move scope to disable leak sanitizer to common place

All scopes dependent on ThreadState have been moved to
thread_state_scopes.h. Move the scope that allows disabling lsan there
as well.

Bug: 982754
Change-Id: I0bc7e095a1d7d572eaeefeeb725b93659e28aa92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1738461
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684497}
parent f53f2c08
......@@ -37,47 +37,9 @@
#include "third_party/blink/renderer/platform/heap/heap_traits.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h"
#include "third_party/blink/renderer/platform/heap/thread_state_scopes.h"
#include "third_party/blink/renderer/platform/heap/trace_traits.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#if defined(LEAK_SANITIZER)
#include "third_party/blink/renderer/platform/wtf/leak_annotations.h"
#endif
namespace blink {
// LEAK_SANITIZER_DISABLED_SCOPE: all allocations made in the current scope
// will be exempted from LSan consideration.
//
// TODO(sof): move this to wtf/LeakAnnotations.h (LeakSanitizer.h?) once
// wtf/ can freely call upon Oilpan functionality.
#if defined(LEAK_SANITIZER)
class LeakSanitizerDisableScope {
STACK_ALLOCATED();
public:
LeakSanitizerDisableScope() {
__lsan_disable();
if (ThreadState::Current())
ThreadState::Current()->enterStaticReferenceRegistrationDisabledScope();
}
~LeakSanitizerDisableScope() {
__lsan_enable();
if (ThreadState::Current())
ThreadState::Current()->leaveStaticReferenceRegistrationDisabledScope();
}
private:
DISALLOW_COPY_AND_ASSIGN(LeakSanitizerDisableScope);
};
#define LEAK_SANITIZER_DISABLED_SCOPE \
LeakSanitizerDisableScope lsanDisabledScope
#else
#define LEAK_SANITIZER_DISABLED_SCOPE
#endif
} // namespace blink
#endif
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HANDLE_H_
......@@ -136,9 +136,6 @@ ThreadState::ThreadState()
reason_for_scheduled_gc_(BlinkGC::GCReason::kForcedGCForTesting),
#if defined(ADDRESS_SANITIZER)
asan_fake_stack_(__asan_get_current_fake_stack()),
#endif
#if defined(LEAK_SANITIZER)
disabled_static_persistent_registration_(0),
#endif
reported_memory_to_v8_(0),
sweeper_scheduler_(base::MakeRefCounted<WorkerPoolTaskRunner>()) {
......@@ -1164,13 +1161,20 @@ void ThreadState::ReportMemoryToV8() {
reported_memory_to_v8_ = current_heap_size;
}
void ThreadState::EnterStaticReferenceRegistrationDisabledScope() {
static_persistent_registration_disabled_count_++;
}
void ThreadState::LeaveStaticReferenceRegistrationDisabledScope() {
DCHECK(static_persistent_registration_disabled_count_);
static_persistent_registration_disabled_count_--;
}
void ThreadState::RegisterStaticPersistentNode(
PersistentNode* node,
PersistentClearCallback callback) {
#if defined(LEAK_SANITIZER)
if (disabled_static_persistent_registration_)
if (static_persistent_registration_disabled_count_)
return;
#endif
DCHECK(!static_persistents_.Contains(node));
static_persistents_.insert(node, callback);
......@@ -1198,17 +1202,6 @@ void ThreadState::FreePersistentNode(PersistentRegion* persistent_region,
DCHECK(!static_persistents_.Contains(persistent_node));
}
#if defined(LEAK_SANITIZER)
void ThreadState::enterStaticReferenceRegistrationDisabledScope() {
disabled_static_persistent_registration_++;
}
void ThreadState::leaveStaticReferenceRegistrationDisabledScope() {
DCHECK(disabled_static_persistent_registration_);
disabled_static_persistent_registration_--;
}
#endif
void ThreadState::InvokePreFinalizers() {
DCHECK(CheckThread());
DCHECK(!SweepForbidden());
......
......@@ -178,6 +178,7 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver {
class AtomicPauseScope;
class GCForbiddenScope;
class LsanDisabledScope;
class MainThreadGCForbiddenScope;
class NoAllocationScope;
class SweepForbiddenScope;
......@@ -377,11 +378,6 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver {
void RegisterStaticPersistentNode(PersistentNode*, PersistentClearCallback);
void ReleaseStaticPersistentNodes();
#if defined(LEAK_SANITIZER)
void enterStaticReferenceRegistrationDisabledScope();
void leaveStaticReferenceRegistrationDisabledScope();
#endif
v8::Isolate* GetIsolate() const { return isolate_; }
// Use CollectAllGarbageForTesting below for testing!
......@@ -478,6 +474,9 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver {
gc_forbidden_count_--;
}
void EnterStaticReferenceRegistrationDisabledScope();
void LeaveStaticReferenceRegistrationDisabledScope();
// The following methods are used to compose RunAtomicPause. Public users
// should use the CollectGarbage entrypoint. Internal users should use these
// methods to compose a full garbage collection.
......@@ -586,6 +585,7 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver {
bool should_optimize_for_load_time_ = false;
size_t no_allocation_count_ = 0;
size_t gc_forbidden_count_ = 0;
size_t static_persistent_registration_disabled_count_ = 0;
base::TimeDelta next_incremental_marking_step_duration_;
base::TimeDelta previous_incremental_marking_time_left_;
......@@ -620,11 +620,6 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver {
// have to clear before initiating LSan's leak detection.
HashMap<PersistentNode*, PersistentClearCallback> static_persistents_;
#if defined(LEAK_SANITIZER)
// Count that controls scoped disabling of persistent registration.
size_t disabled_static_persistent_registration_;
#endif
size_t reported_memory_to_v8_;
int gc_age_ = 0;
......
......@@ -7,6 +7,10 @@
#include "third_party/blink/renderer/platform/heap/thread_state.h"
#if defined(LEAK_SANITIZER)
#include "third_party/blink/renderer/platform/wtf/leak_annotations.h"
#endif
namespace blink {
// The NoAllocationScope class is used in debug mode to catch unwanted
......@@ -87,6 +91,35 @@ class ThreadState::AtomicPauseScope final {
GCForbiddenScope gc_forbidden_scope;
};
#if defined(LEAK_SANITIZER)
class ThreadState::LsanDisabledScope final {
STACK_ALLOCATED();
DISALLOW_COPY_AND_ASSIGN(LsanDisabledScope);
public:
explicit LsanDisabledScope(ThreadState* thread_state)
: thread_state_(thread_state) {
__lsan_disable();
if (thread_state_)
thread_state_->EnterStaticReferenceRegistrationDisabledScope();
}
~LsanDisabledScope() {
__lsan_enable();
if (thread_state_)
thread_state_->LeaveStaticReferenceRegistrationDisabledScope();
}
private:
ThreadState* const thread_state_;
};
#define LEAK_SANITIZER_DISABLED_SCOPE \
ThreadState::LsanDisabledScope lsan_disabled_scope(ThreadState::Current())
#else
#define LEAK_SANITIZER_DISABLED_SCOPE
#endif
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_THREAD_STATE_SCOPES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment