blob: 715b5d23443f25535aac6d45bb8d06a28813263e [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
22#include "constants.h"
23#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:
Shih-wei Liaod1fec812012-02-13 09:51:10 -080033#if defined(ART_USE_LLVM_COMPILER)
34 // Create a CompiledMethod from the oatCompileMethod
35 CompiledMethod(InstructionSet instruction_set,
36 llvm::Function* func);
37#else
Brian Carlstrom0755ec52012-01-11 15:19:46 -080038 // Create a CompiledMethod from the oatCompileMethod
Brian Carlstrom3320cf42011-10-04 14:58:28 -070039 CompiledMethod(InstructionSet instruction_set,
Ian Rogersab058bb2012-03-11 22:19:38 -070040 const std::vector<uint8_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070041 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070042 const uint32_t core_spill_mask,
43 const uint32_t fp_spill_mask,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080044 const std::vector<uint32_t>& mapping_table,
45 const std::vector<uint16_t>& vmap_table);
Shih-wei Liaod1fec812012-02-13 09:51:10 -080046#endif
Brian Carlstrome7d856b2012-01-11 18:10:55 -080047
48 // Add a GC map to a CompiledMethod created by oatCompileMethod
49 void SetGcMap(const std::vector<uint8_t>& gc_map);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070050
Brian Carlstrom0755ec52012-01-11 15:19:46 -080051 // Create a CompiledMethod from the JniCompiler
Brian Carlstrom3320cf42011-10-04 14:58:28 -070052 CompiledMethod(InstructionSet instruction_set,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080053 const std::vector<uint8_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070054 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070055 const uint32_t core_spill_mask,
56 const uint32_t fp_spill_mask);
57
58 ~CompiledMethod();
59
60 InstructionSet GetInstructionSet() const;
61 const std::vector<uint8_t>& GetCode() const;
62 size_t GetFrameSizeInBytes() const;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070063 uint32_t GetCoreSpillMask() const;
64 uint32_t GetFpSpillMask() const;
65 const std::vector<uint32_t>& GetMappingTable() const;
66 const std::vector<uint16_t>& GetVmapTable() const;
Brian Carlstrome7d856b2012-01-11 18:10:55 -080067 const std::vector<uint8_t>& GetGcMap() const;
68
Brian Carlstrom3320cf42011-10-04 14:58:28 -070069 // Aligns an offset from a page aligned value to make it suitable
70 // for code storage. important to ensure that PC relative value
71 // computations work out as expected on ARM.
72 uint32_t AlignCode(uint32_t offset) const;
73 static uint32_t AlignCode(uint32_t offset, InstructionSet instruction_set);
74
75 // returns the difference between the code address and a usable PC.
76 // mainly to cope with kThumb2 where the lower bit must be set.
77 size_t CodeDelta() const;
78
79 // Returns a pointer suitable for invoking the code at the argument
80 // code_pointer address. Mainly to cope with kThumb2 where the
81 // lower bit must be set to indicate Thumb mode.
82 static const void* CodePointer(const void* code_pointer,
83 InstructionSet instruction_set);
84
85 private:
Ian Rogers169c9a72011-11-13 20:13:17 -080086 const InstructionSet instruction_set_;
Shih-wei Liaod1fec812012-02-13 09:51:10 -080087#if defined(ART_USE_LLVM_COMPILER)
88 llvm::Function* func_;
89#endif
Brian Carlstrom3320cf42011-10-04 14:58:28 -070090 std::vector<uint8_t> code_;
Ian Rogers169c9a72011-11-13 20:13:17 -080091 const size_t frame_size_in_bytes_;
92 const uint32_t core_spill_mask_;
93 const uint32_t fp_spill_mask_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070094 std::vector<uint32_t> mapping_table_;
95 std::vector<uint16_t> vmap_table_;
Brian Carlstrome7d856b2012-01-11 18:10:55 -080096 std::vector<uint8_t> gc_map_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070097};
98
99class CompiledInvokeStub {
100 public:
Logan Chienf04364f2012-02-10 12:01:39 +0800101#if defined(ART_USE_LLVM_COMPILER)
102 explicit CompiledInvokeStub(llvm::Function* func);
103#else
Elliott Hughesa51a3dd2011-10-17 15:19:26 -0700104 explicit CompiledInvokeStub(std::vector<uint8_t>& code);
Logan Chienf04364f2012-02-10 12:01:39 +0800105#endif
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700106 ~CompiledInvokeStub();
107 const std::vector<uint8_t>& GetCode() const;
108 private:
Logan Chienf04364f2012-02-10 12:01:39 +0800109#if defined(ART_USE_LLVM_COMPILER)
110 llvm::Function* func_;
111#endif
Shih-wei Liao90d50992012-02-19 03:32:05 -0800112 // TODO: Change the line above from #endif to #else, after oat_writer is
113 // changed.
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700114 std::vector<uint8_t> code_;
115};
116
117} // namespace art
118
119#endif // ART_SRC_COMPILED_METHOD_H_