From 1e7de6cfcabc87ebd36bf6f2c9ed466152d21d4e Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Wed, 21 Oct 2015 12:07:31 +0100 Subject: Remove the magic 32 constant and ensure alignment. Change-Id: I383315bf3cd5f0b8634e2982da55d5d864009a91 --- runtime/jit/jit_code_cache.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'runtime/jit/jit_code_cache.cc') 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(mspace_malloc(code_mspace_, total_size)); + uint8_t* result = reinterpret_cast( + mspace_memalign(code_mspace_, alignment, total_size)); if (result == nullptr) { return nullptr; } - code_ptr = reinterpret_cast( - RoundUp(reinterpret_cast(result + sizeof(OatQuickMethodHeader)), - GetInstructionSetAlignment(kRuntimeISA))); + code_ptr = result + header_size; + DCHECK_ALIGNED_PARAM(reinterpret_cast(code_ptr), alignment); std::copy(code, code + code_size, code_ptr); method_header = reinterpret_cast(code_ptr) - 1; -- cgit v1.2.3-59-g8ed1b