blob: 901ec64d79d6a0669919fdea9a6b24f0c0bf66f0 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Brian Carlstrom3320cf42011-10-04 14:58:28 -070016
17#ifndef ART_SRC_COMPILED_METHOD_H_
18#define ART_SRC_COMPILED_METHOD_H_
19
20#include <vector>
21
Elliott Hughes0f3c5532012-03-30 14:51:51 -070022#include "instruction_set.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070023#include "utils.h"
TDYa127eead4ac2012-06-03 07:15:25 -070024#include "UniquePtr.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070025
Shih-wei Liaod1fec812012-02-13 09:51:10 -080026namespace llvm {
27 class Function;
28}
29
Brian Carlstrom3320cf42011-10-04 14:58:28 -070030namespace art {
31
Logan Chien598c5132012-04-28 22:00:44 +080032class CompiledCode {
33 public:
34 CompiledCode(InstructionSet instruction_set)
Logan Chien971bf3f2012-05-01 15:47:55 +080035 : instruction_set_(instruction_set) {
Logan Chien598c5132012-04-28 22:00:44 +080036 }
37
38 CompiledCode(InstructionSet instruction_set, const std::vector<uint8_t>& code)
Logan Chien971bf3f2012-05-01 15:47:55 +080039 : instruction_set_(instruction_set), code_(code) {
Logan Chien598c5132012-04-28 22:00:44 +080040 CHECK_NE(code.size(), 0U);
41 }
42
Logan Chien598c5132012-04-28 22:00:44 +080043 InstructionSet GetInstructionSet() const {
44 return instruction_set_;
45 }
46
47 const std::vector<uint8_t>& GetCode() const {
48 return code_;
49 }
50
51 void SetCode(const std::vector<uint8_t>& code) {
Logan Chien971bf3f2012-05-01 15:47:55 +080052 CHECK_NE(code.size(), 0U);
Logan Chien598c5132012-04-28 22:00:44 +080053 code_ = code;
54 }
55
56 bool operator==(const CompiledCode& rhs) const {
57 return (code_ == rhs.code_);
58 }
59
Logan Chien598c5132012-04-28 22:00:44 +080060 // To align an offset from a page-aligned value to make it suitable
61 // for code storage. For example on ARM, to ensure that PC relative
62 // valu computations work out as expected.
63 uint32_t AlignCode(uint32_t offset) const;
64 static uint32_t AlignCode(uint32_t offset, InstructionSet instruction_set);
65
66 // returns the difference between the code address and a usable PC.
67 // mainly to cope with kThumb2 where the lower bit must be set.
68 size_t CodeDelta() const;
69
70 // Returns a pointer suitable for invoking the code at the argument
71 // code_pointer address. Mainly to cope with kThumb2 where the
72 // lower bit must be set to indicate Thumb mode.
73 static const void* CodePointer(const void* code_pointer,
74 InstructionSet instruction_set);
75
76 private:
77 const InstructionSet instruction_set_;
78 std::vector<uint8_t> code_;
Logan Chien598c5132012-04-28 22:00:44 +080079};
80
81class CompiledMethod : public CompiledCode {
Brian Carlstrom3320cf42011-10-04 14:58:28 -070082 public:
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -070083 // Constructs a CompiledMethod for the non-LLVM compilers.
Brian Carlstrom3320cf42011-10-04 14:58:28 -070084 CompiledMethod(InstructionSet instruction_set,
Ian Rogersab058bb2012-03-11 22:19:38 -070085 const std::vector<uint8_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070086 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070087 const uint32_t core_spill_mask,
88 const uint32_t fp_spill_mask,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080089 const std::vector<uint32_t>& mapping_table,
Ian Rogers0c7abda2012-09-19 13:33:42 -070090 const std::vector<uint16_t>& vmap_table,
91 const std::vector<uint8_t>& native_gc_map);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070092
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -070093 // Constructs a CompiledMethod for the JniCompiler.
Brian Carlstrom3320cf42011-10-04 14:58:28 -070094 CompiledMethod(InstructionSet instruction_set,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080095 const std::vector<uint8_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070096 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070097 const uint32_t core_spill_mask,
98 const uint32_t fp_spill_mask);
99
Logan Chien6920bce2012-03-17 21:44:01 +0800100 // Constructs a CompiledMethod for the LLVM compiler.
Logan Chien937105a2012-04-02 02:37:37 +0800101 CompiledMethod(InstructionSet instruction_set,
Logan Chien971bf3f2012-05-01 15:47:55 +0800102 const std::vector<uint8_t>& code)
103 : CompiledCode(instruction_set, code),
Logan Chien598c5132012-04-28 22:00:44 +0800104 frame_size_in_bytes_(kStackAlignment), core_spill_mask_(0),
105 fp_spill_mask_(0) {
106 }
Logan Chien6920bce2012-03-17 21:44:01 +0800107
Ian Rogers0c7abda2012-09-19 13:33:42 -0700108 ~CompiledMethod() {}
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700109
Ian Rogers0c7abda2012-09-19 13:33:42 -0700110 size_t GetFrameSizeInBytes() const {
111 return frame_size_in_bytes_;
Logan Chien110bcba2012-04-16 19:11:28 +0800112 }
Ian Rogers0c7abda2012-09-19 13:33:42 -0700113
114 uint32_t GetCoreSpillMask() const {
115 return core_spill_mask_;
116 }
117
118 uint32_t GetFpSpillMask() const {
119 return fp_spill_mask_;
120 }
121
122 const std::vector<uint32_t>& GetMappingTable() const {
123 return mapping_table_;
124 }
125
126 const std::vector<uint16_t>& GetVmapTable() const {
127 return vmap_table_;
128 }
129
130 const std::vector<uint8_t>& GetNativeGcMap() const {
131 return native_gc_map_;
132 }
Logan Chien110bcba2012-04-16 19:11:28 +0800133
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700134 private:
Ian Rogers0c7abda2012-09-19 13:33:42 -0700135 const size_t frame_size_in_bytes_;
Ian Rogers169c9a72011-11-13 20:13:17 -0800136 const uint32_t core_spill_mask_;
137 const uint32_t fp_spill_mask_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700138 std::vector<uint32_t> mapping_table_;
139 std::vector<uint16_t> vmap_table_;
Ian Rogers0c7abda2012-09-19 13:33:42 -0700140 std::vector<uint8_t> native_gc_map_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700141};
142
Logan Chien598c5132012-04-28 22:00:44 +0800143class CompiledInvokeStub : public CompiledCode {
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700144 public:
Logan Chien598c5132012-04-28 22:00:44 +0800145 explicit CompiledInvokeStub(InstructionSet instruction_set);
146
147 explicit CompiledInvokeStub(InstructionSet instruction_set,
148 const std::vector<uint8_t>& code);
149
Ian Rogers0c7abda2012-09-19 13:33:42 -0700150 ~CompiledInvokeStub() {}
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700151};
152
153} // namespace art
154
155#endif // ART_SRC_COMPILED_METHOD_H_