summaryrefslogtreecommitdiff
path: root/libnativeloader/native_loader.cpp
diff options
context:
space:
mode:
author Hans Boehm <hboehm@google.com> 2024-07-19 14:22:50 -0700
committer Hans Boehm <hboehm@google.com> 2024-07-24 19:51:05 +0000
commitc4391b9b54613fa58f14a712f7f4e0fb02c0cb44 (patch)
tree440aa0b1c79048cbbd492e3d9a72c8aabf487f8f /libnativeloader/native_loader.cpp
parentc2ed77e95335a1f03d3aa8dab14e3ef4bf0abb55 (diff)
Avoid redundant GCs and waits when near OOM
This should improve behavior if we are nearly out of memory, and multiple threads detect this at roughly the same time. This seems to be common if system server uses too much memory for some reason. 1) When calling WaitForGcToComplete without holding gc_complete_lock_ only wait for the current GC to complete. Do not wait until no GC is running. This avoids repeated waits when an allocation could actually succeed. 2) If we tried to run a GC, but another thread got in before us, check if we can allocate anyway, rather than treating this as failure and forcing a GC. 3) After we tried to run a last ditch "emergency" GC, also try to allocate again if another thread intervened, rather than insisting on doing our own. We still weakly insist on doing our own before throwing OOME, since we don't know if the other intervening GC cleared soft references, etc. Moved a logging call out of WaitForGcToComplete, since it belongs in the caller. Better documented a couple of almost-incorrect WaitForGcToComplete() calls. Bug: 353333767 Test: testrunner.py --host -b --all-gc --all-debuggable Change-Id: Ie6d8789a4ca94978029f4ddee1a8fc62ea2a0e80
Diffstat (limited to 'libnativeloader/native_loader.cpp')
0 files changed, 0 insertions, 0 deletions