blob: 27011e8955ef8b2c45e020d735cccb8c55958bfc [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;
Vladimir Marko35831e82015-09-11 11:59:18 +010032
33class CompiledMethodStorage {
34 public:
35 explicit CompiledMethodStorage(int swap_fd);
36 ~CompiledMethodStorage();
37
38 void DumpMemoryUsage(std::ostream& os, bool extended) const;
39
40 void SetDedupeEnabled(bool dedupe_enabled) {
41 dedupe_enabled_ = dedupe_enabled;
42 }
43 bool DedupeEnabled() const {
44 return dedupe_enabled_;
45 }
46
47 SwapAllocator<void> GetSwapSpaceAllocator() {
48 return SwapAllocator<void>(swap_space_.get());
49 }
50
51 const LengthPrefixedArray<uint8_t>* DeduplicateCode(const ArrayRef<const uint8_t>& code);
52 void ReleaseCode(const LengthPrefixedArray<uint8_t>* code);
53
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -070054 const LengthPrefixedArray<uint8_t>* DeduplicateMethodInfo(
55 const ArrayRef<const uint8_t>& method_info);
56 void ReleaseMethodInfo(const LengthPrefixedArray<uint8_t>* method_info);
Vladimir Marko35831e82015-09-11 11:59:18 +010057
Vladimir Marko35831e82015-09-11 11:59:18 +010058 const LengthPrefixedArray<uint8_t>* DeduplicateVMapTable(const ArrayRef<const uint8_t>& table);
59 void ReleaseVMapTable(const LengthPrefixedArray<uint8_t>* table);
60
Vladimir Marko35831e82015-09-11 11:59:18 +010061 const LengthPrefixedArray<uint8_t>* DeduplicateCFIInfo(const ArrayRef<const uint8_t>& cfi_info);
62 void ReleaseCFIInfo(const LengthPrefixedArray<uint8_t>* cfi_info);
63
64 const LengthPrefixedArray<LinkerPatch>* DeduplicateLinkerPatches(
65 const ArrayRef<const LinkerPatch>& linker_patches);
66 void ReleaseLinkerPatches(const LengthPrefixedArray<LinkerPatch>* linker_patches);
67
68 private:
69 template <typename T, typename DedupeSetType>
70 const LengthPrefixedArray<T>* AllocateOrDeduplicateArray(const ArrayRef<const T>& data,
71 DedupeSetType* dedupe_set);
72
73 template <typename T>
74 void ReleaseArrayIfNotDeduplicated(const LengthPrefixedArray<T>* array);
75
76 // DeDuplication data structures.
77 template <typename ContentType>
78 class DedupeHashFunc;
79
80 template <typename T>
81 class LengthPrefixedArrayAlloc;
82
83 template <typename T>
84 using ArrayDedupeSet = DedupeSet<ArrayRef<const T>,
85 LengthPrefixedArray<T>,
86 LengthPrefixedArrayAlloc<T>,
87 size_t,
88 DedupeHashFunc<const T>,
89 4>;
90
91 // Swap pool and allocator used for native allocations. May be file-backed. Needs to be first
92 // as other fields rely on this.
93 std::unique_ptr<SwapSpace> swap_space_;
94
95 bool dedupe_enabled_;
96
97 ArrayDedupeSet<uint8_t> dedupe_code_;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -070098 ArrayDedupeSet<uint8_t> dedupe_method_info_;
Vladimir Marko35831e82015-09-11 11:59:18 +010099 ArrayDedupeSet<uint8_t> dedupe_vmap_table_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100100 ArrayDedupeSet<uint8_t> dedupe_cfi_info_;
101 ArrayDedupeSet<LinkerPatch> dedupe_linker_patches_;
102
103 DISALLOW_COPY_AND_ASSIGN(CompiledMethodStorage);
104};
105
106} // namespace art
107
108#endif // ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_