summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2015-10-21 11:14:39 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2015-10-21 11:14:39 +0000
commitd700afabe2ae5c6ac181866a7b461ec06d0258be (patch)
tree24626b6d76bfd3591501932b07b6462c6a2b0733
parent9926d886573d13ab3f97befae4c526b936de8a53 (diff)
parent1e7de6cfcabc87ebd36bf6f2c9ed466152d21d4e (diff)
Merge "Remove the magic 32 constant and ensure alignment."
-rw-r--r--runtime/jit/jit_code_cache.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 7e95e71a5b..4187358bc0 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -129,20 +129,24 @@ uint8_t* JitCodeCache::CommitCode(Thread* self,
size_t fp_spill_mask,
const uint8_t* code,
size_t code_size) {
- size_t total_size = RoundUp(sizeof(OatQuickMethodHeader) + code_size + 32, sizeof(void*));
+ size_t alignment = GetInstructionSetAlignment(kRuntimeISA);
+ // Ensure the header ends up at expected instruction alignment.
+ size_t header_size = RoundUp(sizeof(OatQuickMethodHeader), alignment);
+ size_t total_size = header_size + code_size;
+
OatQuickMethodHeader* method_header = nullptr;
- uint8_t* code_ptr;
+ uint8_t* code_ptr = nullptr;
MutexLock mu(self, lock_);
{
ScopedCodeCacheWrite scc(code_map_.get());
- uint8_t* result = reinterpret_cast<uint8_t*>(mspace_malloc(code_mspace_, total_size));
+ uint8_t* result = reinterpret_cast<uint8_t*>(
+ mspace_memalign(code_mspace_, alignment, total_size));
if (result == nullptr) {
return nullptr;
}
- code_ptr = reinterpret_cast<uint8_t*>(
- RoundUp(reinterpret_cast<size_t>(result + sizeof(OatQuickMethodHeader)),
- GetInstructionSetAlignment(kRuntimeISA)));
+ code_ptr = result + header_size;
+ DCHECK_ALIGNED_PARAM(reinterpret_cast<uintptr_t>(code_ptr), alignment);
std::copy(code, code + code_size, code_ptr);
method_header = reinterpret_cast<OatQuickMethodHeader*>(code_ptr) - 1;