Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 1 | /* |
| 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 Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 23 | #include "base/array_ref.h" |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 24 | #include "base/length_prefixed_array.h" |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 25 | #include "base/macros.h" |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 26 | #include "utils/dedupe_set.h" |
| 27 | #include "utils/swap_space.h" |
| 28 | |
| 29 | namespace art { |
| 30 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 31 | namespace linker { |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 32 | class LinkerPatch; |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 33 | } // namespace linker |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 34 | |
| 35 | class 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 Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 56 | const LengthPrefixedArray<uint8_t>* DeduplicateMethodInfo( |
| 57 | const ArrayRef<const uint8_t>& method_info); |
| 58 | void ReleaseMethodInfo(const LengthPrefixedArray<uint8_t>* method_info); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 59 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 60 | const LengthPrefixedArray<uint8_t>* DeduplicateVMapTable(const ArrayRef<const uint8_t>& table); |
| 61 | void ReleaseVMapTable(const LengthPrefixedArray<uint8_t>* table); |
| 62 | |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 63 | const LengthPrefixedArray<uint8_t>* DeduplicateCFIInfo(const ArrayRef<const uint8_t>& cfi_info); |
| 64 | void ReleaseCFIInfo(const LengthPrefixedArray<uint8_t>* cfi_info); |
| 65 | |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 66 | const LengthPrefixedArray<linker::LinkerPatch>* DeduplicateLinkerPatches( |
| 67 | const ArrayRef<const linker::LinkerPatch>& linker_patches); |
| 68 | void ReleaseLinkerPatches(const LengthPrefixedArray<linker::LinkerPatch>* linker_patches); |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 69 | |
| 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 Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 100 | ArrayDedupeSet<uint8_t> dedupe_method_info_; |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 101 | ArrayDedupeSet<uint8_t> dedupe_vmap_table_; |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 102 | ArrayDedupeSet<uint8_t> dedupe_cfi_info_; |
Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 103 | ArrayDedupeSet<linker::LinkerPatch> dedupe_linker_patches_; |
Vladimir Marko | 35831e8 | 2015-09-11 11:59:18 +0100 | [diff] [blame] | 104 | |
| 105 | DISALLOW_COPY_AND_ASSIGN(CompiledMethodStorage); |
| 106 | }; |
| 107 | |
| 108 | } // namespace art |
| 109 | |
| 110 | #endif // ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_ |