forked from WebPlatformForEmbedded/WPEWebKit
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2.38] limit conservative scan range
Turns out that conservative GC root scanning is going too deep into the stack and this may prevent the collection of objects - see: WebPlatformForEmbedded#1363 The change introduces 'stack guards' that prevent this in particular cases, that is - if there is gloop main loop routine in the stack the GC root stack search will not go deeper that this frame. This avoids some 'false positives' conservative roots that can make the app hold a lot of memory.
- Loading branch information
1 parent
f0b98a4
commit 1c94a4a
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "ConservativeScanStackGuards.h" | ||
|
||
namespace WTF { | ||
std::atomic_bool ConservativeScanStackGuards::active {true}; | ||
thread_local std::deque<void*> ConservativeScanStackGuards::guard_ptr_stack; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
|
||
#include "Logging.h" | ||
|
||
#include <atomic> | ||
#include <deque> | ||
|
||
namespace WTF { | ||
class ConservativeScanStackGuards { | ||
public: | ||
struct ConservativeScanStackGuard { | ||
ConservativeScanStackGuard() { | ||
ConservativeScanStackGuards::setStackGuard(this); | ||
} | ||
~ConservativeScanStackGuard() { | ||
ConservativeScanStackGuards::resetStackGuard(this); | ||
} | ||
|
||
private: | ||
// Prevent heap allocation | ||
void *operator new (size_t); | ||
void *operator new[] (size_t); | ||
void operator delete (void *); | ||
void operator delete[] (void*); | ||
}; | ||
|
||
friend struct ConservativeScanStackGuard; | ||
|
||
static void* updatedStackOrigin(void *stackTop, void *stackOrigin) { | ||
if (!active.load() || guard_ptr_stack.empty()) { | ||
return stackOrigin; | ||
} | ||
|
||
void *ret = stackOrigin; | ||
|
||
void *guard_ptr = guard_ptr_stack.back(); | ||
|
||
if (guard_ptr > stackTop && guard_ptr < stackOrigin) { | ||
WTFLogAlways("ConservativeScanStackGuards: guard IN RANGE: stackTop: %p guard: %p stackOrigin: %p; correcting stackOrigin\n", stackTop, guard_ptr, stackOrigin); | ||
ret = guard_ptr; | ||
} | ||
return ret; | ||
} | ||
|
||
static void setActive(bool act) { | ||
active.store(act); | ||
} | ||
|
||
private: | ||
|
||
static thread_local std::deque<void*> guard_ptr_stack; | ||
static std::atomic_bool active; | ||
|
||
static void setStackGuard(void *ptr) { | ||
guard_ptr_stack.push_back(ptr); | ||
} | ||
|
||
static void resetStackGuard(void *ptr) { | ||
if (ptr != guard_ptr_stack.back()) { | ||
WTFLogAlways("ConservativeScanStackGuards::resetStackGuard expected %p, had: %p", guard_ptr_stack.back(), ptr); | ||
} | ||
guard_ptr_stack.pop_back(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters