blob: 15211e72fa2af4bf560488ec4d22fb5d9745866f [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
25namespace art {
26
27class CompiledMethod {
28 public:
Brian Carlstrom0755ec52012-01-11 15:19:46 -080029 // Create a CompiledMethod from the oatCompileMethod
Brian Carlstrom3320cf42011-10-04 14:58:28 -070030 CompiledMethod(InstructionSet instruction_set,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080031 const std::vector<uint16_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070032 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070033 const uint32_t core_spill_mask,
34 const uint32_t fp_spill_mask,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080035 const std::vector<uint32_t>& mapping_table,
36 const std::vector<uint16_t>& vmap_table);
37
38 // Add a GC map to a CompiledMethod created by oatCompileMethod
39 void SetGcMap(const std::vector<uint8_t>& gc_map);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070040
Brian Carlstrom0755ec52012-01-11 15:19:46 -080041 // Create a CompiledMethod from the JniCompiler
Brian Carlstrom3320cf42011-10-04 14:58:28 -070042 CompiledMethod(InstructionSet instruction_set,
Brian Carlstrome7d856b2012-01-11 18:10:55 -080043 const std::vector<uint8_t>& code,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070044 const size_t frame_size_in_bytes,
Brian Carlstrom3320cf42011-10-04 14:58:28 -070045 const uint32_t core_spill_mask,
46 const uint32_t fp_spill_mask);
47
48 ~CompiledMethod();
49
50 InstructionSet GetInstructionSet() const;
51 const std::vector<uint8_t>& GetCode() const;
52 size_t GetFrameSizeInBytes() const;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070053 uint32_t GetCoreSpillMask() const;
54 uint32_t GetFpSpillMask() const;
55 const std::vector<uint32_t>& GetMappingTable() const;
56 const std::vector<uint16_t>& GetVmapTable() const;
Brian Carlstrome7d856b2012-01-11 18:10:55 -080057 const std::vector<uint8_t>& GetGcMap() const;
58
Brian Carlstrom3320cf42011-10-04 14:58:28 -070059 // Aligns an offset from a page aligned value to make it suitable
60 // for code storage. important to ensure that PC relative value
61 // computations work out as expected on ARM.
62 uint32_t AlignCode(uint32_t offset) const;
63 static uint32_t AlignCode(uint32_t offset, InstructionSet instruction_set);
64
65 // returns the difference between the code address and a usable PC.
66 // mainly to cope with kThumb2 where the lower bit must be set.
67 size_t CodeDelta() const;
68
69 // Returns a pointer suitable for invoking the code at the argument
70 // code_pointer address. Mainly to cope with kThumb2 where the
71 // lower bit must be set to indicate Thumb mode.
72 static const void* CodePointer(const void* code_pointer,
73 InstructionSet instruction_set);
74
75 private:
Ian Rogers169c9a72011-11-13 20:13:17 -080076 const InstructionSet instruction_set_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070077 std::vector<uint8_t> code_;
Ian Rogers169c9a72011-11-13 20:13:17 -080078 const size_t frame_size_in_bytes_;
79 const uint32_t core_spill_mask_;
80 const uint32_t fp_spill_mask_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070081 std::vector<uint32_t> mapping_table_;
82 std::vector<uint16_t> vmap_table_;
Brian Carlstrome7d856b2012-01-11 18:10:55 -080083 std::vector<uint8_t> gc_map_;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070084};
85
86class CompiledInvokeStub {
87 public:
Elliott Hughesa51a3dd2011-10-17 15:19:26 -070088 explicit CompiledInvokeStub(std::vector<uint8_t>& code);
Brian Carlstrom3320cf42011-10-04 14:58:28 -070089 ~CompiledInvokeStub();
90 const std::vector<uint8_t>& GetCode() const;
91 private:
92 std::vector<uint8_t> code_;
93};
94
95} // namespace art
96
97#endif // ART_SRC_COMPILED_METHOD_H_
98