Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 16 | |
| 17 | #ifndef ART_SRC_COMPILED_METHOD_H_ |
| 18 | #define ART_SRC_COMPILED_METHOD_H_ |
| 19 | |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "constants.h" |
| 23 | #include "utils.h" |
| 24 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 25 | namespace llvm { |
| 26 | class Function; |
| 27 | } |
| 28 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 29 | namespace art { |
| 30 | |
| 31 | class CompiledMethod { |
| 32 | public: |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 33 | #if defined(ART_USE_LLVM_COMPILER) |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame^] | 34 | // Constructs a CompiledMethod for the LLVM compiler. |
| 35 | CompiledMethod(InstructionSet instruction_set, llvm::Function* func); |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 36 | #endif |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame^] | 37 | |
| 38 | // Constructs a CompiledMethod for the non-LLVM compilers. |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 39 | CompiledMethod(InstructionSet instruction_set, |
Ian Rogers | ab058bb | 2012-03-11 22:19:38 -0700 | [diff] [blame] | 40 | const std::vector<uint8_t>& code, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 41 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 42 | const uint32_t core_spill_mask, |
| 43 | const uint32_t fp_spill_mask, |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 44 | const std::vector<uint32_t>& mapping_table, |
| 45 | const std::vector<uint16_t>& vmap_table); |
| 46 | |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame^] | 47 | // Sets the GC map for a CompiledMethod. |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 48 | void SetGcMap(const std::vector<uint8_t>& gc_map); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 49 | |
Elliott Hughes | 3fa1b7e | 2012-03-13 17:06:22 -0700 | [diff] [blame^] | 50 | // Constructs a CompiledMethod for the JniCompiler. |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 51 | CompiledMethod(InstructionSet instruction_set, |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 52 | const std::vector<uint8_t>& code, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 53 | const size_t frame_size_in_bytes, |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 54 | const uint32_t core_spill_mask, |
| 55 | const uint32_t fp_spill_mask); |
| 56 | |
| 57 | ~CompiledMethod(); |
| 58 | |
| 59 | InstructionSet GetInstructionSet() const; |
| 60 | const std::vector<uint8_t>& GetCode() const; |
| 61 | size_t GetFrameSizeInBytes() const; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 62 | 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 Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 66 | const std::vector<uint8_t>& GetGcMap() const; |
| 67 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 68 | // Aligns an offset from a page aligned value to make it suitable |
| 69 | // for code storage. important to ensure that PC relative value |
| 70 | // computations work out as expected on ARM. |
| 71 | uint32_t AlignCode(uint32_t offset) const; |
| 72 | static uint32_t AlignCode(uint32_t offset, InstructionSet instruction_set); |
| 73 | |
| 74 | // returns the difference between the code address and a usable PC. |
| 75 | // mainly to cope with kThumb2 where the lower bit must be set. |
| 76 | size_t CodeDelta() const; |
| 77 | |
| 78 | // Returns a pointer suitable for invoking the code at the argument |
| 79 | // code_pointer address. Mainly to cope with kThumb2 where the |
| 80 | // lower bit must be set to indicate Thumb mode. |
| 81 | static const void* CodePointer(const void* code_pointer, |
| 82 | InstructionSet instruction_set); |
| 83 | |
| 84 | private: |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 85 | const InstructionSet instruction_set_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 86 | #if defined(ART_USE_LLVM_COMPILER) |
| 87 | llvm::Function* func_; |
| 88 | #endif |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 89 | std::vector<uint8_t> code_; |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 90 | const size_t frame_size_in_bytes_; |
| 91 | const uint32_t core_spill_mask_; |
| 92 | const uint32_t fp_spill_mask_; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 93 | std::vector<uint32_t> mapping_table_; |
| 94 | std::vector<uint16_t> vmap_table_; |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 95 | std::vector<uint8_t> gc_map_; |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | class CompiledInvokeStub { |
| 99 | public: |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 100 | #if defined(ART_USE_LLVM_COMPILER) |
| 101 | explicit CompiledInvokeStub(llvm::Function* func); |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 102 | #endif |
Shih-wei Liao | c4c9881 | 2012-03-10 21:55:51 -0800 | [diff] [blame] | 103 | explicit CompiledInvokeStub(std::vector<uint8_t>& code); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 104 | ~CompiledInvokeStub(); |
| 105 | const std::vector<uint8_t>& GetCode() const; |
| 106 | private: |
Logan Chien | f04364f | 2012-02-10 12:01:39 +0800 | [diff] [blame] | 107 | #if defined(ART_USE_LLVM_COMPILER) |
| 108 | llvm::Function* func_; |
| 109 | #endif |
Shih-wei Liao | 90d5099 | 2012-02-19 03:32:05 -0800 | [diff] [blame] | 110 | // TODO: Change the line above from #endif to #else, after oat_writer is |
| 111 | // changed. |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 112 | std::vector<uint8_t> code_; |
| 113 | }; |
| 114 | |
| 115 | } // namespace art |
| 116 | |
| 117 | #endif // ART_SRC_COMPILED_METHOD_H_ |