summaryrefslogtreecommitdiffstats
path: root/runtime/mem_map_test.cc
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2014-05-19 17:01:13 -0700
committerAndreas Gampe <agampe@google.com>2014-05-20 11:18:01 -0700
commitd8f26dbebe72c1cbdfa85bdeeb003283c7435db3 (patch)
treed752729ef80ed46877681874ac69b3e846f34078 /runtime/mem_map_test.cc
parentfd1264475562006c93b651d33e0a6266e8093ebe (diff)
downloadart-d8f26dbebe72c1cbdfa85bdeeb003283c7435db3.tar.gz
art-d8f26dbebe72c1cbdfa85bdeeb003283c7435db3.tar.bz2
art-d8f26dbebe72c1cbdfa85bdeeb003283c7435db3.zip
ART: Randomize mem_map start address for linear scan search
When using linear scan for mem_map, randomize the start of the search with getauxval(AT_RANDOM). Change-Id: Id1e4c86b928147d74b9b0b73ff704de5d87b4500
Diffstat (limited to 'runtime/mem_map_test.cc')
-rw-r--r--runtime/mem_map_test.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/runtime/mem_map_test.cc b/runtime/mem_map_test.cc
index c07a9a3842..c108a5f67c 100644
--- a/runtime/mem_map_test.cc
+++ b/runtime/mem_map_test.cc
@@ -84,8 +84,41 @@ class MemMapTest : public testing::Test {
}
delete m1;
}
+
+#if defined(__LP64__) && !defined(__x86_64__)
+ static uintptr_t GetLinearScanPos() {
+ return MemMap::next_mem_pos_;
+ }
+#endif
};
+#if defined(__LP64__) && !defined(__x86_64__)
+
+#ifdef __BIONIC__
+extern uintptr_t CreateStartPos(uint64_t input);
+#endif
+
+TEST_F(MemMapTest, Start) {
+ uintptr_t start = GetLinearScanPos();
+ EXPECT_LE(64 * KB, start);
+ EXPECT_LT(start, static_cast<uintptr_t>(ART_BASE_ADDRESS));
+
+#ifdef __BIONIC__
+ // Test a couple of values. Make sure they are different.
+ uintptr_t last = 0;
+ for (size_t i = 0; i < 100; ++i) {
+ uintptr_t random_start = CreateStartPos(i * kPageSize);
+ EXPECT_NE(last, random_start);
+ last = random_start;
+ }
+
+ // Even on max, should be below ART_BASE_ADDRESS.
+ EXPECT_LT(CreateStartPos(~0), static_cast<uintptr_t>(ART_BASE_ADDRESS));
+#endif
+ // End of test.
+}
+#endif
+
TEST_F(MemMapTest, MapAnonymousEmpty) {
std::string error_msg;
std::unique_ptr<MemMap> map(MemMap::MapAnonymous("MapAnonymousEmpty",