/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_ #define ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_ #include #include #include #include "base/array_ref.h" #include "base/length_prefixed_array.h" #include "base/macros.h" #include "utils/dedupe_set.h" #include "utils/swap_space.h" namespace art { namespace linker { class LinkerPatch; } // namespace linker class CompiledMethodStorage { public: explicit CompiledMethodStorage(int swap_fd); ~CompiledMethodStorage(); void DumpMemoryUsage(std::ostream& os, bool extended) const; void SetDedupeEnabled(bool dedupe_enabled) { dedupe_enabled_ = dedupe_enabled; } bool DedupeEnabled() const { return dedupe_enabled_; } SwapAllocator GetSwapSpaceAllocator() { return SwapAllocator(swap_space_.get()); } const LengthPrefixedArray* DeduplicateCode(const ArrayRef& code); void ReleaseCode(const LengthPrefixedArray* code); const LengthPrefixedArray* DeduplicateVMapTable(const ArrayRef& table); void ReleaseVMapTable(const LengthPrefixedArray* table); const LengthPrefixedArray* DeduplicateCFIInfo(const ArrayRef& cfi_info); void ReleaseCFIInfo(const LengthPrefixedArray* cfi_info); const LengthPrefixedArray* DeduplicateLinkerPatches( const ArrayRef& linker_patches); void ReleaseLinkerPatches(const LengthPrefixedArray* linker_patches); // Returns the code associated with the given patch. // If the code has not been set, returns empty data. // If `debug_name` is not null, stores the associated debug name in `*debug_name`. ArrayRef GetThunkCode(const linker::LinkerPatch& linker_patch, /*out*/ std::string* debug_name = nullptr); // Sets the code and debug name associated with the given patch. void SetThunkCode(const linker::LinkerPatch& linker_patch, ArrayRef code, const std::string& debug_name); private: class ThunkMapKey; class ThunkMapValue; using ThunkMapValueType = std::pair; using ThunkMap = std::map, SwapAllocator>; static_assert(std::is_same::value, "Value type check."); static ThunkMapKey GetThunkMapKey(const linker::LinkerPatch& linker_patch); template const LengthPrefixedArray* AllocateOrDeduplicateArray(const ArrayRef& data, DedupeSetType* dedupe_set); template void ReleaseArrayIfNotDeduplicated(const LengthPrefixedArray* array); // DeDuplication data structures. template class DedupeHashFunc; template class LengthPrefixedArrayAlloc; template using ArrayDedupeSet = DedupeSet, LengthPrefixedArray, LengthPrefixedArrayAlloc, size_t, DedupeHashFunc, 4>; // Swap pool and allocator used for native allocations. May be file-backed. Needs to be first // as other fields rely on this. std::unique_ptr swap_space_; bool dedupe_enabled_; ArrayDedupeSet dedupe_code_; ArrayDedupeSet dedupe_vmap_table_; ArrayDedupeSet dedupe_cfi_info_; ArrayDedupeSet dedupe_linker_patches_; Mutex thunk_map_lock_; ThunkMap thunk_map_ GUARDED_BY(thunk_map_lock_); DISALLOW_COPY_AND_ASSIGN(CompiledMethodStorage); }; } // namespace art #endif // ART_COMPILER_DRIVER_COMPILED_METHOD_STORAGE_H_