blob: 249f06c20f35c5954f0ae168e027ff06ed55a9d5 [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
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010031namespace linker {
Vladimir Marko35831e82015-09-11 11:59:18 +010032class LinkerPatch;
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010033} // namespace linker
Vladimir Marko35831e82015-09-11 11:59:18 +010034
35class CompiledMethodStorage {
36 public:
37 explicit CompiledMethodStorage(int swap_fd);
38 ~CompiledMethodStorage();
39
40 void DumpMemoryUsage(std::ostream& os, bool extended) const;
41
42 void SetDedupeEnabled(bool dedupe_enabled) {
43 dedupe_enabled_ = dedupe_enabled;
44 }
45 bool DedupeEnabled() const {
46 return dedupe_enabled_;
47 }
48
49 SwapAllocator<void> GetSwapSpaceAllocator() {
50 return SwapAllocator<void>(swap_space_.get());
51 }
52
53 const LengthPrefixedArray<uint8_t>* DeduplicateCode(const ArrayRef<const uint8_t>& code);
54 void ReleaseCode(const LengthPrefixedArray<uint8_t>* code);
55
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -070056 const LengthPrefixedArray<uint8_t>* DeduplicateMethodInfo(
57 const ArrayRef<const uint8_t>& method_info);
58 void ReleaseMethodInfo(const LengthPrefixedArray<uint8_t>* method_info);
Vladimir Marko35831e82015-09-11 11:59:18 +010059
Vladimir Marko35831e82015-09-11 11:59:18 +010060 const LengthPrefixedArray<uint8_t>* DeduplicateVMapTable(const ArrayRef<const uint8_t>& table);
61 void ReleaseVMapTable(const LengthPrefixedArray<uint8_t>* table);
62
Vladimir Marko35831e82015-09-11 11:59:18 +010063 const LengthPrefixedArray<uint8_t>* DeduplicateCFIInfo(const ArrayRef<const uint8_t>& cfi_info);
64 void ReleaseCFIInfo(const LengthPrefixedArray<uint8_t>* cfi_info);
65
Vladimir Markod8dbc8d2017-09-20 13:37:47 +010066 const LengthPrefixedArray<linker::LinkerPatch>* DeduplicateLinkerPatches(
67 const ArrayRef<const linker::LinkerPatch>& linker_patches);
68 void ReleaseLinkerPatches(const LengthPrefixedArray<linker::LinkerPatch>* linker_patches);
Vladimir Marko35831e82015-09-11 11:59:18 +010069
70 private:
71 template <typename T, typename DedupeSetType>
72 const LengthPrefixedArray<T>* AllocateOrDeduplicateArray(const ArrayRef<const T>& data,
73 DedupeSetType* dedupe_set);
74
75 template <typename T>
76 void ReleaseArrayIfNotDeduplicated(const LengthPrefixedArray<T>* array);
77
78 // DeDuplication data structures.
79 template <typename ContentType>
80 class DedupeHashFunc;
81
82 template <typename T>
83 class LengthPrefixedArrayAlloc;
84
85 template <typename T>
86 using ArrayDedupeSet = DedupeSet<ArrayRef<const T>,
87 LengthPrefixedArray<T>,
88 LengthPrefixedArrayAlloc<T>,
89 size_t,
90 DedupeHashFunc<const T>,
91 4>;
92
93 // Swap pool and allocator used for native allocations. May be file-backed. Needs to be first
94 // as other fields rely on this.
95 std::unique_ptr<SwapSpace> swap_space_;
96
97 bool dedupe_enabled_;
98
99 ArrayDedupeSet<uint8_t> dedupe_code_;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700100 ArrayDedupeSet<uint8_t> dedupe_method_info_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100101 ArrayDedupeSet<uint8_t> dedupe_vmap_table_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100102 ArrayDedupeSet<uint8_t> dedupe_cfi_info_;
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100103 ArrayDedupeSet<linker::LinkerPatch> dedupe_linker_patches_;
Vladimir Marko35831e82015-09-11 11:59:18 +0100104
105 DISALLOW_COPY_AND_ASSIGN(CompiledMethodStorage);
106};
107
108} // namespace art
109
110#endif // ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_