• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "compiled_method.h"
18 
19 #include "driver/compiled_method_storage.h"
20 #include "utils/swap_space.h"
21 
22 namespace art {
23 
CompiledCode(CompiledMethodStorage * storage,InstructionSet instruction_set,const ArrayRef<const uint8_t> & quick_code)24 CompiledCode::CompiledCode(CompiledMethodStorage* storage,
25                            InstructionSet instruction_set,
26                            const ArrayRef<const uint8_t>& quick_code)
27     : storage_(storage),
28       quick_code_(storage->DeduplicateCode(quick_code)),
29       packed_fields_(InstructionSetField::Encode(instruction_set)) {
30 }
31 
~CompiledCode()32 CompiledCode::~CompiledCode() {
33   GetStorage()->ReleaseCode(quick_code_);
34 }
35 
operator ==(const CompiledCode & rhs) const36 bool CompiledCode::operator==(const CompiledCode& rhs) const {
37   if (quick_code_ != nullptr) {
38     if (rhs.quick_code_ == nullptr) {
39       return false;
40     } else if (quick_code_->size() != rhs.quick_code_->size()) {
41       return false;
42     } else {
43       return std::equal(quick_code_->begin(), quick_code_->end(), rhs.quick_code_->begin());
44     }
45   }
46   return (rhs.quick_code_ == nullptr);
47 }
48 
AlignCode(size_t offset) const49 size_t CompiledCode::AlignCode(size_t offset) const {
50   return AlignCode(offset, GetInstructionSet());
51 }
52 
AlignCode(size_t offset,InstructionSet instruction_set)53 size_t CompiledCode::AlignCode(size_t offset, InstructionSet instruction_set) {
54   return RoundUp(offset, GetInstructionSetCodeAlignment(instruction_set));
55 }
56 
GetEntryPointAdjustment() const57 size_t CompiledCode::GetEntryPointAdjustment() const {
58   return GetInstructionSetEntryPointAdjustment(GetInstructionSet());
59 }
60 
CompiledMethod(CompiledMethodStorage * storage,InstructionSet instruction_set,const ArrayRef<const uint8_t> & quick_code,const ArrayRef<const uint8_t> & vmap_table,const ArrayRef<const uint8_t> & cfi_info,const ArrayRef<const linker::LinkerPatch> & patches)61 CompiledMethod::CompiledMethod(CompiledMethodStorage* storage,
62                                InstructionSet instruction_set,
63                                const ArrayRef<const uint8_t>& quick_code,
64                                const ArrayRef<const uint8_t>& vmap_table,
65                                const ArrayRef<const uint8_t>& cfi_info,
66                                const ArrayRef<const linker::LinkerPatch>& patches)
67     : CompiledCode(storage, instruction_set, quick_code),
68       vmap_table_(storage->DeduplicateVMapTable(vmap_table)),
69       cfi_info_(storage->DeduplicateCFIInfo(cfi_info)),
70       patches_(storage->DeduplicateLinkerPatches(patches)) {
71 }
72 
SwapAllocCompiledMethod(CompiledMethodStorage * storage,InstructionSet instruction_set,const ArrayRef<const uint8_t> & quick_code,const ArrayRef<const uint8_t> & vmap_table,const ArrayRef<const uint8_t> & cfi_info,const ArrayRef<const linker::LinkerPatch> & patches)73 CompiledMethod* CompiledMethod::SwapAllocCompiledMethod(
74     CompiledMethodStorage* storage,
75     InstructionSet instruction_set,
76     const ArrayRef<const uint8_t>& quick_code,
77     const ArrayRef<const uint8_t>& vmap_table,
78     const ArrayRef<const uint8_t>& cfi_info,
79     const ArrayRef<const linker::LinkerPatch>& patches) {
80   SwapAllocator<CompiledMethod> alloc(storage->GetSwapSpaceAllocator());
81   CompiledMethod* ret = alloc.allocate(1);
82   alloc.construct(ret,
83                   storage,
84                   instruction_set,
85                   quick_code,
86                   vmap_table,
87                   cfi_info, patches);
88   return ret;
89 }
90 
ReleaseSwapAllocatedCompiledMethod(CompiledMethodStorage * storage,CompiledMethod * m)91 void CompiledMethod::ReleaseSwapAllocatedCompiledMethod(CompiledMethodStorage* storage,
92                                                         CompiledMethod* m) {
93   SwapAllocator<CompiledMethod> alloc(storage->GetSwapSpaceAllocator());
94   alloc.destroy(m);
95   alloc.deallocate(m, 1);
96 }
97 
~CompiledMethod()98 CompiledMethod::~CompiledMethod() {
99   CompiledMethodStorage* storage = GetStorage();
100   storage->ReleaseLinkerPatches(patches_);
101   storage->ReleaseCFIInfo(cfi_info_);
102   storage->ReleaseVMapTable(vmap_table_);
103 }
104 
105 }  // namespace art
106