blob: 060af723a759e921c28652f12d0aff97ffcf8c21 [file] [log] [blame]
Mathieu Chartier193bad92013-08-29 18:46:00 -07001/*
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#include "driver/compiler_driver.h"
19
20namespace art {
21
22CompiledCode::CompiledCode(CompilerDriver* compiler_driver, InstructionSet instruction_set,
Dave Allisond6ed6422014-04-09 23:36:15 +000023 const std::vector<uint8_t>& quick_code)
Ian Rogersef7d42f2014-01-06 12:55:46 -080024 : compiler_driver_(compiler_driver), instruction_set_(instruction_set),
Elliott Hughes956af0f2014-12-11 14:34:28 -080025 quick_code_(nullptr) {
26 SetCode(&quick_code);
Mathieu Chartier193bad92013-08-29 18:46:00 -070027}
28
Elliott Hughes956af0f2014-12-11 14:34:28 -080029void CompiledCode::SetCode(const std::vector<uint8_t>* quick_code) {
Ian Rogersef7d42f2014-01-06 12:55:46 -080030 if (quick_code != nullptr) {
31 CHECK(!quick_code->empty());
32 quick_code_ = compiler_driver_->DeduplicateCode(*quick_code);
33 }
34}
35
36bool 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 }
Ian Rogersef7d42f2014-01-06 12:55:46 -080045 }
Elliott Hughes956af0f2014-12-11 14:34:28 -080046 return (rhs.quick_code_ == nullptr);
Mathieu Chartier193bad92013-08-29 18:46:00 -070047}
48
49uint32_t CompiledCode::AlignCode(uint32_t offset) const {
50 return AlignCode(offset, instruction_set_);
51}
52
53uint32_t CompiledCode::AlignCode(uint32_t offset, InstructionSet instruction_set) {
Andreas Gampeaf13ad92014-04-11 12:07:48 -070054 return RoundUp(offset, GetInstructionSetAlignment(instruction_set));
Mathieu Chartier193bad92013-08-29 18:46:00 -070055}
56
57size_t CompiledCode::CodeDelta() const {
Dave Allison50abf0a2014-06-23 13:19:59 -070058 return CodeDelta(instruction_set_);
59}
60
61size_t CompiledCode::CodeDelta(InstructionSet instruction_set) {
62 switch (instruction_set) {
Mathieu Chartier193bad92013-08-29 18:46:00 -070063 case kArm:
Stuart Monteithb95a5342014-03-12 13:32:32 +000064 case kArm64:
Mathieu Chartier193bad92013-08-29 18:46:00 -070065 case kMips:
66 case kX86:
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070067 case kX86_64:
Mathieu Chartier193bad92013-08-29 18:46:00 -070068 return 0;
69 case kThumb2: {
70 // +1 to set the low-order bit so a BLX will switch to Thumb mode
71 return 1;
72 }
73 default:
Dave Allison50abf0a2014-06-23 13:19:59 -070074 LOG(FATAL) << "Unknown InstructionSet: " << instruction_set;
Mathieu Chartier193bad92013-08-29 18:46:00 -070075 return 0;
76 }
77}
78
79const void* CompiledCode::CodePointer(const void* code_pointer,
80 InstructionSet instruction_set) {
81 switch (instruction_set) {
82 case kArm:
Stuart Monteithb95a5342014-03-12 13:32:32 +000083 case kArm64:
Mathieu Chartier193bad92013-08-29 18:46:00 -070084 case kMips:
85 case kX86:
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070086 case kX86_64:
Mathieu Chartier193bad92013-08-29 18:46:00 -070087 return code_pointer;
88 case kThumb2: {
89 uintptr_t address = reinterpret_cast<uintptr_t>(code_pointer);
90 // Set the low-order bit so a BLX will switch to Thumb mode
91 address |= 0x1;
92 return reinterpret_cast<const void*>(address);
93 }
94 default:
95 LOG(FATAL) << "Unknown InstructionSet: " << instruction_set;
96 return NULL;
97 }
98}
99
Mathieu Chartier193bad92013-08-29 18:46:00 -0700100const std::vector<uint32_t>& CompiledCode::GetOatdataOffsetsToCompliledCodeOffset() const {
Elliott Hughes956af0f2014-12-11 14:34:28 -0800101 CHECK_NE(0U, oatdata_offsets_to_compiled_code_offset_.size());
Mathieu Chartier193bad92013-08-29 18:46:00 -0700102 return oatdata_offsets_to_compiled_code_offset_;
103}
104
105void CompiledCode::AddOatdataOffsetToCompliledCodeOffset(uint32_t offset) {
106 oatdata_offsets_to_compiled_code_offset_.push_back(offset);
107}
Mathieu Chartier193bad92013-08-29 18:46:00 -0700108
Ian Rogers72d32622014-05-06 16:20:11 -0700109CompiledMethod::CompiledMethod(CompilerDriver* driver,
Mathieu Chartier193bad92013-08-29 18:46:00 -0700110 InstructionSet instruction_set,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800111 const std::vector<uint8_t>& quick_code,
Mathieu Chartier193bad92013-08-29 18:46:00 -0700112 const size_t frame_size_in_bytes,
113 const uint32_t core_spill_mask,
114 const uint32_t fp_spill_mask,
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700115 SrcMap* src_mapping_table,
Mathieu Chartier193bad92013-08-29 18:46:00 -0700116 const std::vector<uint8_t>& mapping_table,
117 const std::vector<uint8_t>& vmap_table,
Mark Mendellae9fd932014-02-10 16:14:35 -0800118 const std::vector<uint8_t>& native_gc_map,
Vladimir Markof4da6752014-08-01 19:04:18 +0100119 const std::vector<uint8_t>* cfi_info,
120 const ArrayRef<LinkerPatch>& patches)
Ian Rogers72d32622014-05-06 16:20:11 -0700121 : CompiledCode(driver, instruction_set, quick_code), frame_size_in_bytes_(frame_size_in_bytes),
Mathieu Chartier193bad92013-08-29 18:46:00 -0700122 core_spill_mask_(core_spill_mask), fp_spill_mask_(fp_spill_mask),
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700123 src_mapping_table_(driver->DeduplicateSrcMappingTable(src_mapping_table->Arrange())),
124 mapping_table_(driver->DeduplicateMappingTable(mapping_table)),
125 vmap_table_(driver->DeduplicateVMapTable(vmap_table)),
126 gc_map_(driver->DeduplicateGCMap(native_gc_map)),
Vladimir Markof4da6752014-08-01 19:04:18 +0100127 cfi_info_(driver->DeduplicateCFIInfo(cfi_info)),
128 patches_(patches.begin(), patches.end()) {
Mathieu Chartier193bad92013-08-29 18:46:00 -0700129}
130
Ian Rogers72d32622014-05-06 16:20:11 -0700131CompiledMethod::CompiledMethod(CompilerDriver* driver,
Mathieu Chartier193bad92013-08-29 18:46:00 -0700132 InstructionSet instruction_set,
Nicolas Geoffray39468442014-09-02 15:17:15 +0100133 const std::vector<uint8_t>& quick_code,
134 const size_t frame_size_in_bytes,
135 const uint32_t core_spill_mask,
136 const uint32_t fp_spill_mask,
Nicolas Geoffray39468442014-09-02 15:17:15 +0100137 const std::vector<uint8_t>& stack_map)
138 : CompiledCode(driver, instruction_set, quick_code),
139 frame_size_in_bytes_(frame_size_in_bytes),
140 core_spill_mask_(core_spill_mask),
141 fp_spill_mask_(fp_spill_mask),
142 src_mapping_table_(driver->DeduplicateSrcMappingTable(SrcMap())),
Nicolas Geoffray376b2bb2014-12-09 14:26:32 +0000143 mapping_table_(nullptr),
Nicolas Geoffray39468442014-09-02 15:17:15 +0100144 vmap_table_(driver->DeduplicateVMapTable(stack_map)),
145 gc_map_(nullptr),
Vladimir Markof4da6752014-08-01 19:04:18 +0100146 cfi_info_(nullptr),
147 patches_() {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100148}
149
150CompiledMethod::CompiledMethod(CompilerDriver* driver,
151 InstructionSet instruction_set,
Mathieu Chartier193bad92013-08-29 18:46:00 -0700152 const std::vector<uint8_t>& code,
153 const size_t frame_size_in_bytes,
154 const uint32_t core_spill_mask,
Tong Shen547cdfd2014-08-05 01:54:19 -0700155 const uint32_t fp_spill_mask,
156 const std::vector<uint8_t>* cfi_info)
Ian Rogers72d32622014-05-06 16:20:11 -0700157 : CompiledCode(driver, instruction_set, code),
Mathieu Chartier193bad92013-08-29 18:46:00 -0700158 frame_size_in_bytes_(frame_size_in_bytes),
Mark Mendellae9fd932014-02-10 16:14:35 -0800159 core_spill_mask_(core_spill_mask), fp_spill_mask_(fp_spill_mask),
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700160 src_mapping_table_(driver->DeduplicateSrcMappingTable(SrcMap())),
Ian Rogers72d32622014-05-06 16:20:11 -0700161 mapping_table_(driver->DeduplicateMappingTable(std::vector<uint8_t>())),
162 vmap_table_(driver->DeduplicateVMapTable(std::vector<uint8_t>())),
163 gc_map_(driver->DeduplicateGCMap(std::vector<uint8_t>())),
Vladimir Markof4da6752014-08-01 19:04:18 +0100164 cfi_info_(driver->DeduplicateCFIInfo(cfi_info)),
165 patches_() {
Mathieu Chartier193bad92013-08-29 18:46:00 -0700166}
167
Mathieu Chartier193bad92013-08-29 18:46:00 -0700168} // namespace art