Skip to content

Commit ec6def5

Browse files
mralephCommit Queue
authored and
Commit Queue
committed
[vm] Explicitly exclude interrupt related state in PRODUCT
This is follow up for the previous change somewhat incorrectly used FLAG_profiler in ~OSThread to determine whether we need to delete interrupter related state. FLAG_profiler is mutable in non-PRODUCT builds so this could create memory leak. TEST=testing PRODUCT and non-PRODUCT builds manually Change-Id: Icf5ca6b83daab91daa125755261700ba2dbb9533 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328422 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Slava Egorov <[email protected]>
1 parent 9f7ae42 commit ec6def5

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

runtime/vm/dart_api_impl.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,19 +1593,23 @@ DART_EXPORT void Dart_StopProfiling() {
15931593
}
15941594

15951595
DART_EXPORT void Dart_ThreadDisableProfiling() {
1596+
#if !defined(PRODUCT)
15961597
OSThread* os_thread = OSThread::Current();
15971598
if (os_thread == nullptr) {
15981599
return;
15991600
}
16001601
os_thread->DisableThreadInterrupts();
1602+
#endif // !defined(PRODUCT)
16011603
}
16021604

16031605
DART_EXPORT void Dart_ThreadEnableProfiling() {
1606+
#if !defined(PRODUCT)
16041607
OSThread* os_thread = OSThread::Current();
16051608
if (os_thread == nullptr) {
16061609
return;
16071610
}
16081611
os_thread->EnableThreadInterrupts();
1612+
#endif // !defined(PRODUCT)
16091613
}
16101614

16111615
DART_EXPORT void Dart_AddSymbols(const char* dso_name,

runtime/vm/os_thread.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ OSThread::OSThread()
4343
#endif
4444
name_(OSThread::GetCurrentThreadName()),
4545
timeline_block_lock_(),
46-
thread_interrupt_disabled_(1), // Thread interrupts disabled by default.
4746
log_(new class Log()) {
4847
// Try to get accurate stack bounds from pthreads, etc.
4948
if (!GetCurrentStackBounds(&stack_limit_, &stack_base_)) {
@@ -97,11 +96,13 @@ OSThread::~OSThread() {
9796
#endif
9897
timeline_block_ = nullptr;
9998
free(name_);
100-
if (FLAG_profiler && prepared_for_interrupts_) {
99+
#if !defined(PRODUCT)
100+
if (prepared_for_interrupts_) {
101101
ThreadInterrupter::CleanupCurrentThreadState(thread_interrupter_state_);
102102
thread_interrupter_state_ = nullptr;
103103
prepared_for_interrupts_ = false;
104104
}
105+
#endif // !defined(PRODUCT)
105106
}
106107

107108
void OSThread::SetName(const char* name) {
@@ -132,6 +133,7 @@ uword OSThread::GetCurrentStackPointer() {
132133
return stack_allocated_local;
133134
}
134135

136+
#if !defined(PRODUCT)
135137
void OSThread::DisableThreadInterrupts() {
136138
ASSERT(OSThread::Current() == this);
137139
thread_interrupt_disabled_.fetch_add(1u);
@@ -159,6 +161,7 @@ void OSThread::EnableThreadInterrupts() {
159161
bool OSThread::ThreadInterruptsEnabled() {
160162
return thread_interrupt_disabled_ == 0;
161163
}
164+
#endif // !defined(PRODUCT)
162165

163166
static void DeleteThread(void* thread) {
164167
MSAN_UNPOISON(&thread, sizeof(thread));

runtime/vm/os_thread.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ class OSThread : public BaseThread {
148148
static void SetCurrentSafestackPointer(uword ssp);
149149
#endif
150150

151+
#if !defined(PRODUCT)
151152
// Used to temporarily disable or enable thread interrupts.
152153
void DisableThreadInterrupts();
153154
void EnableThreadInterrupts();
154155
bool ThreadInterruptsEnabled();
156+
#endif // !defined(PRODUCT)
155157

156158
// The currently executing thread, or nullptr if not yet initialized.
157159
static OSThread* TryCurrent() {
@@ -296,9 +298,13 @@ class OSThread : public BaseThread {
296298
// All |Thread|s are registered in the thread list.
297299
OSThread* thread_list_next_ = nullptr;
298300

299-
RelaxedAtomic<uintptr_t> thread_interrupt_disabled_;
301+
#if !defined(PRODUCT)
302+
// Thread interrupts disabled by default.
303+
RelaxedAtomic<uintptr_t> thread_interrupt_disabled_ = {1};
300304
bool prepared_for_interrupts_ = false;
301305
void* thread_interrupter_state_ = nullptr;
306+
#endif // !defined(PRODUCT)
307+
302308
Log* log_;
303309
uword stack_base_ = 0;
304310
uword stack_limit_ = 0;

runtime/vm/thread.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void Thread::ResumeThreadInternal(Thread* thread) {
561561
thread->set_os_thread(os_thread);
562562
os_thread->set_thread(thread);
563563
Thread::SetCurrent(thread);
564-
os_thread->EnableThreadInterrupts();
564+
NOT_IN_PRODUCT(os_thread->EnableThreadInterrupts());
565565

566566
#if !defined(PRODUCT) || defined(FORCE_INCLUDE_SAMPLING_HEAP_PROFILER)
567567
thread->heap_sampler().Initialize();
@@ -577,7 +577,7 @@ void Thread::SuspendThreadInternal(Thread* thread, VMTag::VMTagId tag) {
577577

578578
OSThread* os_thread = thread->os_thread();
579579
ASSERT(os_thread != nullptr);
580-
os_thread->DisableThreadInterrupts();
580+
NOT_IN_PRODUCT(os_thread->DisableThreadInterrupts());
581581
os_thread->set_thread(nullptr);
582582
OSThread::SetCurrent(os_thread);
583583
thread->set_os_thread(nullptr);
@@ -1389,6 +1389,7 @@ void Thread::ResetDartMutatorState(Isolate* isolate) {
13891389
ONLY_IN_PRECOMPILED(dispatch_table_array_ = nullptr);
13901390
}
13911391

1392+
#if !defined(PRODUCT)
13921393
DisableThreadInterruptsScope::DisableThreadInterruptsScope(Thread* thread)
13931394
: StackResource(thread) {
13941395
if (thread != nullptr) {
@@ -1405,6 +1406,7 @@ DisableThreadInterruptsScope::~DisableThreadInterruptsScope() {
14051406
os_thread->EnableThreadInterrupts();
14061407
}
14071408
}
1409+
#endif
14081410

14091411
NoReloadScope::NoReloadScope(Thread* thread) : ThreadStackResource(thread) {
14101412
#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)

runtime/vm/thread.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,12 +1498,21 @@ class RuntimeCallDeoptScope : public StackResource {
14981498
void WindowsThreadCleanUp();
14991499
#endif
15001500

1501+
#if !defined(PRODUCT)
15011502
// Disable thread interrupts.
15021503
class DisableThreadInterruptsScope : public StackResource {
15031504
public:
15041505
explicit DisableThreadInterruptsScope(Thread* thread);
15051506
~DisableThreadInterruptsScope();
15061507
};
1508+
#else
1509+
class DisableThreadInterruptsScope : public StackResource {
1510+
public:
1511+
explicit DisableThreadInterruptsScope(Thread* thread)
1512+
: StackResource(thread) {}
1513+
~DisableThreadInterruptsScope() {}
1514+
};
1515+
#endif // !defined(PRODUCT)
15071516

15081517
// Within a NoSafepointScope, the thread must not reach any safepoint. Used
15091518
// around code that manipulates raw object pointers directly without handles.

0 commit comments

Comments
 (0)