blob: 892bc592db080000d888e4b4cebfdc02718df9d1 [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
Mathieu Chartier193bad92013-08-29 18:46:00 -070017#ifndef ART_COMPILER_COMPILED_METHOD_H_
18#define ART_COMPILER_COMPILED_METHOD_H_
Brian Carlstrom3320cf42011-10-04 14:58:28 -070019
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070020#include <memory>
Brian Carlstrom265091e2013-01-30 14:08:26 -080021#include <string>
Brian Carlstrom3320cf42011-10-04 14:58:28 -070022#include <vector>
23
Ian Rogersd582fa42014-11-05 23:46:43 -080024#include "arch/instruction_set.h"
Brian Carlstrom3320cf42011-10-04 14:58:28 -070025
26namespace art {
27
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010028template <typename T> class ArrayRef;
Mathieu Chartier193bad92013-08-29 18:46:00 -070029class CompilerDriver;
Vladimir Marko35831e82015-09-11 11:59:18 +010030class CompiledMethodStorage;
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010031template<typename T> class LengthPrefixedArray;
32
33namespace linker {
34class LinkerPatch;
35} // namespace linker
Mathieu Chartier193bad92013-08-29 18:46:00 -070036
Logan Chien598c5132012-04-28 22:00:44 +080037class CompiledCode {
38 public:
Brian Carlstrom265091e2013-01-30 14:08:26 -080039 // For Quick to supply an code blob
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010040 CompiledCode(CompilerDriver* compiler_driver,
41 InstructionSet instruction_set,
Vladimir Marko35831e82015-09-11 11:59:18 +010042 const ArrayRef<const uint8_t>& quick_code);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080043
44 virtual ~CompiledCode();
Logan Chien598c5132012-04-28 22:00:44 +080045
Logan Chien598c5132012-04-28 22:00:44 +080046 InstructionSet GetInstructionSet() const {
47 return instruction_set_;
48 }
49
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010050 ArrayRef<const uint8_t> GetQuickCode() const;
Logan Chien598c5132012-04-28 22:00:44 +080051
Ian Rogersef7d42f2014-01-06 12:55:46 -080052 bool operator==(const CompiledCode& rhs) const;
53
Logan Chien598c5132012-04-28 22:00:44 +080054 // To align an offset from a page-aligned value to make it suitable
55 // for code storage. For example on ARM, to ensure that PC relative
56 // valu computations work out as expected.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080057 size_t AlignCode(size_t offset) const;
58 static size_t AlignCode(size_t offset, InstructionSet instruction_set);
Logan Chien598c5132012-04-28 22:00:44 +080059
60 // returns the difference between the code address and a usable PC.
61 // mainly to cope with kThumb2 where the lower bit must be set.
62 size_t CodeDelta() const;
Dave Allison50abf0a2014-06-23 13:19:59 -070063 static size_t CodeDelta(InstructionSet instruction_set);
Logan Chien598c5132012-04-28 22:00:44 +080064
65 // Returns a pointer suitable for invoking the code at the argument
66 // code_pointer address. Mainly to cope with kThumb2 where the
67 // lower bit must be set to indicate Thumb mode.
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010068 static const void* CodePointer(const void* code_pointer, InstructionSet instruction_set);
Logan Chien598c5132012-04-28 22:00:44 +080069
Vladimir Marko35831e82015-09-11 11:59:18 +010070 protected:
71 template <typename T>
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010072 static ArrayRef<const T> GetArray(const LengthPrefixedArray<T>* array);
Vladimir Marko35831e82015-09-11 11:59:18 +010073
74 CompilerDriver* GetCompilerDriver() {
75 return compiler_driver_;
76 }
Brian Carlstrom265091e2013-01-30 14:08:26 -080077
Logan Chien598c5132012-04-28 22:00:44 +080078 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -080079 CompilerDriver* const compiler_driver_;
Mathieu Chartier193bad92013-08-29 18:46:00 -070080
Logan Chien598c5132012-04-28 22:00:44 +080081 const InstructionSet instruction_set_;
Brian Carlstrom8227cc12013-03-06 14:26:48 -080082
Ian Rogersef7d42f2014-01-06 12:55:46 -080083 // Used to store the PIC code for Quick.
Vladimir Marko35831e82015-09-11 11:59:18 +010084 const LengthPrefixedArray<uint8_t>* const quick_code_;
Logan Chien598c5132012-04-28 22:00:44 +080085};
86
Yevgeny Roubane3ea8382014-08-08 16:29:38 +070087class CompiledMethod FINAL : public CompiledCode {
Brian Carlstrom3320cf42011-10-04 14:58:28 -070088 public:
Andreas Gampee21dc3d2014-12-08 16:59:43 -080089 // Constructs a CompiledMethod.
90 // Note: Consider using the static allocation methods below that will allocate the CompiledMethod
91 // in the swap space.
Ian Rogers72d32622014-05-06 16:20:11 -070092 CompiledMethod(CompilerDriver* driver,
Mathieu Chartier193bad92013-08-29 18:46:00 -070093 InstructionSet instruction_set,
Andreas Gampee21dc3d2014-12-08 16:59:43 -080094 const ArrayRef<const uint8_t>& quick_code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070095 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070096 const uint32_t core_spill_mask,
97 const uint32_t fp_spill_mask,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -070098 const ArrayRef<const uint8_t>& method_info,
Andreas Gampee21dc3d2014-12-08 16:59:43 -080099 const ArrayRef<const uint8_t>& vmap_table,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800100 const ArrayRef<const uint8_t>& cfi_info,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100101 const ArrayRef<const linker::LinkerPatch>& patches);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700102
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800103 virtual ~CompiledMethod();
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700104
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800105 static CompiledMethod* SwapAllocCompiledMethod(
106 CompilerDriver* driver,
107 InstructionSet instruction_set,
108 const ArrayRef<const uint8_t>& quick_code,
109 const size_t frame_size_in_bytes,
110 const uint32_t core_spill_mask,
111 const uint32_t fp_spill_mask,
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700112 const ArrayRef<const uint8_t>& method_info,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800113 const ArrayRef<const uint8_t>& vmap_table,
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800114 const ArrayRef<const uint8_t>& cfi_info,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100115 const ArrayRef<const linker::LinkerPatch>& patches);
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800116
117 static void ReleaseSwapAllocatedCompiledMethod(CompilerDriver* driver, CompiledMethod* m);
118
Ian Rogers0c7abda2012-09-19 13:33:42 -0700119 size_t GetFrameSizeInBytes() const {
120 return frame_size_in_bytes_;
Logan Chien110bcba2012-04-16 19:11:28 +0800121 }
Ian Rogers0c7abda2012-09-19 13:33:42 -0700122
123 uint32_t GetCoreSpillMask() const {
124 return core_spill_mask_;
125 }
126
127 uint32_t GetFpSpillMask() const {
128 return fp_spill_mask_;
129 }
130
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100131 ArrayRef<const uint8_t> GetMethodInfo() const;
Yevgeny Roubane3ea8382014-08-08 16:29:38 +0700132
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100133 ArrayRef<const uint8_t> GetVmapTable() const;
Ian Rogers0c7abda2012-09-19 13:33:42 -0700134
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100135 ArrayRef<const uint8_t> GetCFIInfo() const;
Mark Mendellae9fd932014-02-10 16:14:35 -0800136
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100137 ArrayRef<const linker::LinkerPatch> GetPatches() const;
Vladimir Markof4da6752014-08-01 19:04:18 +0100138
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700139 private:
Ian Rogersa1827042013-04-18 16:36:43 -0700140 // For quick code, the size of the activation used by the code.
Ian Rogers0c7abda2012-09-19 13:33:42 -0700141 const size_t frame_size_in_bytes_;
Ian Rogersa1827042013-04-18 16:36:43 -0700142 // For quick code, a bit mask describing spilled GPR callee-save registers.
Ian Rogers169c9a72011-11-13 20:13:17 -0800143 const uint32_t core_spill_mask_;
Ian Rogersa1827042013-04-18 16:36:43 -0700144 // For quick code, a bit mask describing spilled FPR callee-save registers.
Ian Rogers169c9a72011-11-13 20:13:17 -0800145 const uint32_t fp_spill_mask_;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700146 // For quick code, method specific information that is not very dedupe friendly (method indices).
147 const LengthPrefixedArray<uint8_t>* const method_info_;
148 // For quick code, holds code infos which contain stack maps, inline information, and etc.
Vladimir Marko35831e82015-09-11 11:59:18 +0100149 const LengthPrefixedArray<uint8_t>* const vmap_table_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800150 // For quick code, a FDE entry for the debug_frame section.
Vladimir Marko35831e82015-09-11 11:59:18 +0100151 const LengthPrefixedArray<uint8_t>* const cfi_info_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100152 // For quick code, linker patches needed by the method.
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100153 const LengthPrefixedArray<linker::LinkerPatch>* const patches_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700154};
155
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700156} // namespace art
157
Mathieu Chartier193bad92013-08-29 18:46:00 -0700158#endif // ART_COMPILER_COMPILED_METHOD_H_