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.
ARRISEOS-45892 limit conservative scan range (#410)
* ARRISEOS-45892 limit conservative scan range Turns out that conservative GC root scanning is scanning too deep into the stack & this results in GC being prevented (for more details see the ticket & upstream issue: WebPlatformForEmbedded#1363 This workaround introduces 'stack guards' that prevent this in particular cases, that is - if there is gloop main loop routine in the stack (see RunLoopGLib), the GC root search will not go deeper that this frame. This is enough to make GC work when invoked synchronously, via VM::shrinkFootprintWhenIdle; therefore for the workaround to work, wpe plugin needs to call that (another part of the workaround is implemented in WebKitBrowser plugin) * ARRISEOS-45892 limit conservative scan range Small correction: immediate garbageCollectNow is still useful, since under heavy load shrinkFootprintWhenIdle might be executed quite late.
- Loading branch information
1 parent
cb064e9
commit 6379f88
Showing
6 changed files
with
82 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
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