blob: d6961a0876cc870ea4433cb2242785cc99f8d765 [file] [log] [blame]
Vladimir Marko35831e82015-09-11 11:59:18 +01001/*
2 * Copyright (C) 2015 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 */
16
17#ifndef ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_
18#define ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_
19
20#include <iosfwd>
21#include <memory>
22
Alex Lighte64300b2015-12-15 15:02:47 -080023#include "base/length_prefixed_array.h"
Vladimir Marko35831e82015-09-11 11:59:18 +010024#include "base/macros.h"
Vladimir Marko35831e82015-09-11 11:59:18 +010025#include "utils/array_ref.h"
26#include "utils/dedupe_set.h"
27#include "utils/swap_space.h"
28
29namespace art {
30
31class LinkerPatch;
32class SrcMapElem;
33
34class CompiledMethodStorage {
35 public:
36 explicit CompiledMethodStorage(int swap_fd);
37 ~CompiledMethodStorage();
38
39 void DumpMemoryUsage(std::ostream& os, bool extended) const;
40
41 void SetDedupeEnabled(bool dedupe_enabled) {
42 dedupe_enabled_ = dedupe_enabled;
43 }
44 bool DedupeEnabled() const {
45 return dedupe_enabled_;
46 }
47
48 SwapAllocator<void> GetSwapSpaceAllocator() {
49 return SwapAllocator<void>(swap_space_.get());
50 }
51
52 const LengthPrefixedArray<uint8_t>* DeduplicateCode(const ArrayRef<const uint8_t>& code);
53 void ReleaseCode(const LengthPrefixedArray<uint8_t>* code);
54
55 const LengthPrefixedArray<SrcMapElem>* DeduplicateSrcMappingTable(
56 const ArrayRef<const SrcMapElem>& src_map);
57 void ReleaseSrcMappingTable(const LengthPrefixedArray<SrcMapElem>* src_map);
58
59 const LengthPrefixedArray<uint8_t>* DeduplicateMappingTable(const ArrayRef<const uint8_t>& table);
60 void ReleaseMappingTable(const LengthPrefixedArray<uint8_t>* table);
61
62 const LengthPrefixedArray<uint8_t>* DeduplicateVMapTable(const ArrayRef<const uint8_t>& table);
63 void ReleaseVMapTable(const LengthPrefixedArray<uint8_t>* table);
64
65 const LengthPrefixedArray<uint8_t>* DeduplicateGCMap(const ArrayRef<const uint8_t>& gc_map);
66 void ReleaseGCMap(const LengthPrefixedArray<uint8_t>* gc_map);
67
68 const LengthPrefixedArray<uint8_t>* DeduplicateCFIInfo(const ArrayRef<const uint8_t>& cfi_info);
69 void ReleaseCFIInfo(const LengthPrefixedArray<uint8_t>* cfi_info);
70
71 const LengthPrefixedArray<LinkerPatch>* DeduplicateLinkerPatches(
72 const ArrayRef<const LinkerPatch>& linker_patches);
73 void ReleaseLinkerPatches(const LengthPrefixedArray<LinkerPatch>* linker_patches);
74
75 private:
76 template <typename T, typename DedupeSetType>
77 const LengthPrefixedArray<T>* AllocateOrDeduplicateArray(const ArrayRef<const T>& data,
78 DedupeSetType* dedupe_set);
79
80 template <typename T>
81 void ReleaseArrayIfNotDeduplicated(const LengthPrefixedArray<T>* array);
82
83 // DeDuplication data structures.
84 template <typename ContentType>
85 class DedupeHashFunc;
86
87 template <typename T>
88 class LengthPrefixedArrayAlloc;
89
90 template <typename T>
91 using ArrayDedupeSet = DedupeSet<ArrayRef<const T>,
92 LengthPrefixedArray<T>,
93 LengthPrefixedArrayAlloc<T>,
94 size_t,
95 DedupeHashFunc<const T>,
96 4>;
97
98 // Swap pool and allocator used for native allocations. May be file-backed. Needs to be first
99 // as other fields rely on this.
100 std::unique_ptr<SwapSpace> swap_space_;
101
102 bool dedupe_enabled_;
103
104 ArrayDedupeSet<uint8_t> dedupe_code_;
105 ArrayDedupeSet<SrcMapElem> dedupe_src_mapping_table_;
106 ArrayDedupeSet<uint8_t> dedupe_mapping_table_;
107 ArrayDedupeSet<uint8_t> dedupe_vmap_table_;
108 ArrayDedupeSet<uint8_t> dedupe_gc_map_;
109 ArrayDedupeSet<uint8_t> dedupe_cfi_info_;
110 ArrayDedupeSet<LinkerPatch> dedupe_linker_patches_;
111
112 DISALLOW_COPY_AND_ASSIGN(CompiledMethodStorage);
113};
114
115} // namespace art
116
117#endif // ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_