summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2023-07-17 14:51:54 +0100
committer Nicolas Geoffray <ngeoffray@google.com> 2023-07-20 12:24:55 +0000
commitf450fb45fd33bac9d6accad1b5cd657422946259 (patch)
tree3e66179ed5727afd8a993e531d9a1d7249d2abbb
parentc01e312bd183604552a2dc435940f12e38be6a17 (diff)
Adjust some tests which were relying on non-deterministic behavior.
Test: gtests Bug: 291273982 Change-Id: Ie8dbfa67c908df2209265680a904e21d77b3798d
-rw-r--r--runtime/gc/heap_test.cc5
-rw-r--r--runtime/gc/verification.cc15
2 files changed, 19 insertions, 1 deletions
diff --git a/runtime/gc/heap_test.cc b/runtime/gc/heap_test.cc
index b569241bdc..57358e6ef1 100644
--- a/runtime/gc/heap_test.cc
+++ b/runtime/gc/heap_test.cc
@@ -111,6 +111,7 @@ bool AnyIsFalse(bool x, bool y) { return !x || !y; }
TEST_F(HeapTest, GCMetrics) {
// Allocate a few string objects (to be collected), then trigger garbage
// collection, and check that GC metrics are updated (where applicable).
+ Heap* heap = Runtime::Current()->GetHeap();
{
constexpr const size_t kNumObj = 128;
ScopedObjectAccess soa(Thread::Current());
@@ -119,8 +120,10 @@ TEST_F(HeapTest, GCMetrics) {
Handle<mirror::String> string [[maybe_unused]] (
hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "test")));
}
+ // Do one GC while the temporary objects cannot be collected. This GC will age the objects,and
+ // ensure that the GC at line 127 does scan the objects.
+ heap->CollectGarbage(/* clear_soft_references= */ false);
}
- Heap* heap = Runtime::Current()->GetHeap();
heap->CollectGarbage(/* clear_soft_references= */ false);
// ART Metrics.
diff --git a/runtime/gc/verification.cc b/runtime/gc/verification.cc
index ad04860c57..8ef61cbea0 100644
--- a/runtime/gc/verification.cc
+++ b/runtime/gc/verification.cc
@@ -33,6 +33,21 @@ std::string Verification::DumpRAMAroundAddress(uintptr_t addr, uintptr_t bytes)
uintptr_t* dump_end = reinterpret_cast<uintptr_t*>(addr + bytes);
std::ostringstream oss;
oss << " adjacent_ram=";
+
+ {
+ // Check if the RAM is accessible.
+ android::base::unique_fd read_fd, write_fd;
+ if (!android::base::Pipe(&read_fd, &write_fd)) {
+ LOG(WARNING) << "Could not create pipe, RAM being dumped may be unaccessible";
+ } else {
+ size_t count = 2 * bytes;
+ if (write(write_fd.get(), dump_start, count) != static_cast<ssize_t>(count)) {
+ oss << "unaccessible";
+ dump_start = dump_end;
+ }
+ }
+ }
+
for (const uintptr_t* p = dump_start; p < dump_end; ++p) {
if (p == reinterpret_cast<uintptr_t*>(addr)) {
// Marker of where the address is.