summaryrefslogtreecommitdiffstats
path: root/lldb/source/Expression/IRMemoryMap.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2014-07-09 16:42:27 +0000
committerZachary Turner <zturner@google.com>2014-07-09 16:42:27 +0000
commit3ddcd314f25060dafefcf6c5142f1fe49d37f9fb (patch)
tree97a159a5715a23e6c4aa968c19546c81771d5175 /lldb/source/Expression/IRMemoryMap.cpp
parent58814445d4a43d9ab8a2adba5309d6affd378101 (diff)
downloadbcm5719-llvm-3ddcd314f25060dafefcf6c5142f1fe49d37f9fb.tar.gz
bcm5719-llvm-3ddcd314f25060dafefcf6c5142f1fe49d37f9fb.zip
Dont' use a random probe & alloc strategy for the IRMemoryMap.
The current strategy for host allocation is to choose a random address and attempt to allocate there, eventually failing if the allocation cannot be satisfied. The C standard only guarantees that RAND_MAX >= 32767, so for platforms that use a very small RAND_MAX allocations will fail with very high probability. On such platforms (Windows is one), you can reproduce this trivially by running lldb, typing "expr (3)" and then hitting enter you see a failure. Failures generally happen with a frequency of about 1 failure every 5 evaluations. There is no good reason that allocations need to look like "real" pointers, so this patch changes the allocation scheme to simply jump straight to the end and grab a free chunk of memory. Reviewed By: Sean Callanan Differential Revision: http://reviews.llvm.org/D4300 llvm-svn: 212630
Diffstat (limited to 'lldb/source/Expression/IRMemoryMap.cpp')
-rw-r--r--lldb/source/Expression/IRMemoryMap.cpp38
1 files changed, 8 insertions, 30 deletions
diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp
index 9239e087b6e..a4fe7a96837 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -53,6 +53,8 @@ IRMemoryMap::FindSpace (size_t size)
lldb::ProcessSP process_sp = m_process_wp.lock();
lldb::addr_t ret = LLDB_INVALID_ADDRESS;
+ if (size == 0)
+ return ret;
if (process_sp && process_sp->CanJIT() && process_sp->IsAlive())
{
@@ -66,37 +68,13 @@ IRMemoryMap::FindSpace (size_t size)
return ret;
}
- for (int iterations = 0; iterations < 16; ++iterations)
+ ret = 0;
+ if (!m_allocations.empty())
{
- lldb::addr_t candidate = LLDB_INVALID_ADDRESS;
-
- switch (target_sp->GetArchitecture().GetAddressByteSize())
- {
- case 4:
- {
- uint32_t random_data = rand();
- candidate = random_data;
- candidate &= ~0xfffull;
- break;
- }
- case 8:
- {
- uint32_t random_low = rand();
- uint32_t random_high = rand();
- candidate = random_high;
- candidate <<= 32ull;
- candidate |= random_low;
- candidate &= ~0xfffull;
- break;
- }
- }
-
- if (IntersectsAllocation(candidate, size))
- continue;
-
- ret = candidate;
-
- return ret;
+ auto back = m_allocations.rbegin();
+ lldb::addr_t addr = back->first;
+ size_t alloc_size = back->second.m_size;
+ ret = llvm::RoundUpToAlignment(addr+alloc_size, 4096);
}
return ret;
OpenPOWER on IntegriCloud