blob: 124b5a6e25abbaf41656886f876d2978ecc72108 [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
David Brazdild9c90372016-09-14 16:53:55 +010023#include "base/array_ref.h"
Alex Lighte64300b2015-12-15 15:02:47 -080024#include "base/length_prefixed_array.h"
Vladimir Marko35831e82015-09-11 11:59:18 +010025#include "base/macros.h"
Vladimir Marko35831e82015-09-11 11:59:18 +010026#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
Vladimir Marko35831e82015-09-11 11:59:18 +010059 const LengthPrefixedArray<uint8_t>* DeduplicateVMapTable(const ArrayRef<const uint8_t>& table);
60 void ReleaseVMapTable(const LengthPrefixedArray<uint8_t>* table);
61
Vladimir Marko35831e82015-09-11 11:59:18 +010062 const LengthPrefixedArray<uint8_t>* DeduplicateCFIInfo(const ArrayRef<const uint8_t>& cfi_info);
63 void ReleaseCFIInfo(const LengthPrefixedArray<uint8_t>* cfi_info);
64
65 const LengthPrefixedArray<LinkerPatch>* DeduplicateLinkerPatches(
66 const ArrayRef<const LinkerPatch>& linker_patches);
67 void ReleaseLinkerPatches(const LengthPrefixedArray<LinkerPatch>* linker_patches);
68
69 private:
70 template <typename T, typename DedupeSetType>
71 const LengthPrefixedArray<T>* AllocateOrDeduplicateArray(const ArrayRef<const T>& data,
72 DedupeSetType* dedupe_set);
73
74 template <typename T>
75 void ReleaseArrayIfNotDeduplicated(const LengthPrefixedArray<T>* array);
76
77 // DeDuplication data structures.
78 template <typename ContentType>
79 class DedupeHashFunc;
80
81 template <typename T>
82 class LengthPrefixedArrayAlloc;
83
84 template <typename T>
85 using ArrayDedupeSet = DedupeSet<ArrayRef<const T>,
86 LengthPrefixedArray<T>,
87 LengthPrefixedArrayAlloc<T>,
88 size_t,
89 DedupeHashFunc<const T>,
90 4>;
91
92 // Swap pool and allocator used for native allocations. May be file-backed. Needs to be first
93 // as other fields rely on this.
94 std::unique_ptr<SwapSpace> swap_space_;
95
96 bool dedupe_enabled_;
97
98 ArrayDedupeSet<uint8_t> dedupe_code_;
99 ArrayDedupeSet<SrcMapElem> dedupe_src_mapping_table_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100100 ArrayDedupeSet<uint8_t> dedupe_vmap_table_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100101 ArrayDedupeSet<uint8_t> dedupe_cfi_info_;
102 ArrayDedupeSet<LinkerPatch> dedupe_linker_patches_;
103
104 DISALLOW_COPY_AND_ASSIGN(CompiledMethodStorage);
105};
106
107} // namespace art
108
109#endif // ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_