blob: 96dfa00c2d2bd3f279e0adb72e0c24ce172d1622 [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"
24
Shih-wei Liaod1fec812012-02-13 09:51:10 -080025namespace llvm {
26 class Function;
27}
28
Brian Carlstrom3320cf42011-10-04 14:58:28 -070029namespace art {
30
31class CompiledMethod {
32 public:
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -070033 // Constructs a CompiledMethod for the non-LLVM compilers.
Brian Carlstrom3320cf42011-10-04 14:58:28 -070034 CompiledMethod(InstructionSet instruction_set,
Ian Rogersab058bb2012-03-11 22:19:38 -070035 const std::vector<uint8_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070036 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070037 const uint32_t core_spill_mask,
38 const uint32_t fp_spill_mask,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080039 const std::vector<uint32_t>& mapping_table,
40 const std::vector<uint16_t>& vmap_table);
41
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -070042 // Sets the GC map for a CompiledMethod.
Brian Carlstrome7d856b2012-01-11 18:10:55 -080043 void SetGcMap(const std::vector<uint8_t>& gc_map);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070044
Elliott Hughes3fa1b7e2012-03-13 17:06:22 -070045 // Constructs a CompiledMethod for the JniCompiler.
Brian Carlstrom3320cf42011-10-04 14:58:28 -070046 CompiledMethod(InstructionSet instruction_set,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080047 const std::vector<uint8_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070048 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070049 const uint32_t core_spill_mask,
50 const uint32_t fp_spill_mask);
51
Logan Chien6920bce2012-03-17 21:44:01 +080052 // Constructs a CompiledMethod for the LLVM compiler.
Logan Chien937105a2012-04-02 02:37:37 +080053 CompiledMethod(InstructionSet instruction_set,
54 const uint16_t elf_idx,
55 const uint16_t elf_func_idx);
Logan Chien6920bce2012-03-17 21:44:01 +080056
Brian Carlstrom3320cf42011-10-04 14:58:28 -070057 ~CompiledMethod();
58
59 InstructionSet GetInstructionSet() const;
60 const std::vector<uint8_t>& GetCode() const;
61 size_t GetFrameSizeInBytes() const;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070062 uint32_t GetCoreSpillMask() const;
63 uint32_t GetFpSpillMask() const;
64 const std::vector<uint32_t>& GetMappingTable() const;
65 const std::vector<uint16_t>& GetVmapTable() const;
Brian Carlstrome7d856b2012-01-11 18:10:55 -080066 const std::vector<uint8_t>& GetGcMap() const;
67
Logan Chien110bcba2012-04-16 19:11:28 +080068#if defined(ART_USE_LLVM_COMPILER)
69 void SetFrameSizeInBytes(size_t new_frame_size_in_bytes) {
70 frame_size_in_bytes_ = new_frame_size_in_bytes;
71 }
72#endif
73
Brian Carlstrom3320cf42011-10-04 14:58:28 -070074 // Aligns an offset from a page aligned value to make it suitable
75 // for code storage. important to ensure that PC relative value
76 // computations work out as expected on ARM.
77 uint32_t AlignCode(uint32_t offset) const;
78 static uint32_t AlignCode(uint32_t offset, InstructionSet instruction_set);
79
80 // returns the difference between the code address and a usable PC.
81 // mainly to cope with kThumb2 where the lower bit must be set.
82 size_t CodeDelta() const;
83
84 // Returns a pointer suitable for invoking the code at the argument
85 // code_pointer address. Mainly to cope with kThumb2 where the
86 // lower bit must be set to indicate Thumb mode.
87 static const void* CodePointer(const void* code_pointer,
88 InstructionSet instruction_set);
89
Logan Chien937105a2012-04-02 02:37:37 +080090 uint16_t GetElfIndex() const {
91 DCHECK(IsExecutableInElf());
Logan Chien6920bce2012-03-17 21:44:01 +080092 return elf_idx_;
93 }
94
Logan Chien937105a2012-04-02 02:37:37 +080095 uint16_t GetElfFuncIndex() const {
96 DCHECK(IsExecutableInElf());
97 return elf_func_idx_;
98 }
99
Logan Chien6920bce2012-03-17 21:44:01 +0800100 bool IsExecutableInElf() const {
Logan Chien937105a2012-04-02 02:37:37 +0800101 return (elf_idx_ != static_cast<uint16_t>(-1u));
Logan Chien6920bce2012-03-17 21:44:01 +0800102 }
103
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700104 private:
Logan Chien6920bce2012-03-17 21:44:01 +0800105 // For non-LLVM
Ian Rogers169c9a72011-11-13 20:13:17 -0800106 const InstructionSet instruction_set_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700107 std::vector<uint8_t> code_;
Logan Chien110bcba2012-04-16 19:11:28 +0800108 size_t frame_size_in_bytes_;
Ian Rogers169c9a72011-11-13 20:13:17 -0800109 const uint32_t core_spill_mask_;
110 const uint32_t fp_spill_mask_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700111 std::vector<uint32_t> mapping_table_;
112 std::vector<uint16_t> vmap_table_;
Brian Carlstrome7d856b2012-01-11 18:10:55 -0800113 std::vector<uint8_t> gc_map_;
Logan Chien6920bce2012-03-17 21:44:01 +0800114 // For LLVM
Logan Chien937105a2012-04-02 02:37:37 +0800115 uint16_t elf_idx_;
116 uint16_t elf_func_idx_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700117};
118
119class CompiledInvokeStub {
120 public:
Shih-wei Liaoc4c98812012-03-10 21:55:51 -0800121 explicit CompiledInvokeStub(std::vector<uint8_t>& code);
Logan Chienf04364f2012-02-10 12:01:39 +0800122#if defined(ART_USE_LLVM_COMPILER)
Logan Chien937105a2012-04-02 02:37:37 +0800123 explicit CompiledInvokeStub(uint16_t elf_idx, uint16_t elf_func_idx);
Logan Chienf04364f2012-02-10 12:01:39 +0800124#endif
Logan Chien6920bce2012-03-17 21:44:01 +0800125 ~CompiledInvokeStub();
126
127 const std::vector<uint8_t>& GetCode() const;
128
Logan Chien937105a2012-04-02 02:37:37 +0800129 uint16_t GetElfIndex() const {
130 DCHECK(IsExecutableInElf());
Logan Chien6920bce2012-03-17 21:44:01 +0800131 return elf_idx_;
132 }
133
Logan Chien937105a2012-04-02 02:37:37 +0800134 uint16_t GetElfFuncIndex() const {
135 DCHECK(IsExecutableInElf());
136 return elf_func_idx_;
137 }
138
Logan Chien6920bce2012-03-17 21:44:01 +0800139 bool IsExecutableInElf() const {
Logan Chien937105a2012-04-02 02:37:37 +0800140 return (elf_idx_ != static_cast<uint16_t>(-1u));
Logan Chien6920bce2012-03-17 21:44:01 +0800141 }
142
143 private:
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700144 std::vector<uint8_t> code_;
Logan Chien937105a2012-04-02 02:37:37 +0800145 uint16_t elf_idx_;
146 uint16_t elf_func_idx_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700147};
148
149} // namespace art
150
151#endif // ART_SRC_COMPILED_METHOD_H_