From e21dc3db191df04c100620965bee4617b3b24397 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Mon, 8 Dec 2014 16:59:43 -0800 Subject: ART: Swap-space in the compiler Introduce a swap-space and corresponding allocator to transparently switch native allocations to memory backed by a file. Bug: 18596910 (cherry picked from commit 62746d8d9c4400e4764f162b22bfb1a32be287a9) Change-Id: I131448f3907115054a592af73db86d2b9257ea33 --- compiler/compiled_method.h | 121 +++++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 42 deletions(-) (limited to 'compiler/compiled_method.h') diff --git a/compiler/compiled_method.h b/compiler/compiled_method.h index d93db03806..6013507ac4 100644 --- a/compiler/compiled_method.h +++ b/compiler/compiled_method.h @@ -25,6 +25,7 @@ #include "method_reference.h" #include "utils.h" #include "utils/array_ref.h" +#include "utils/swap_space.h" namespace llvm { class Function; @@ -38,17 +39,17 @@ class CompiledCode { public: // For Quick to supply an code blob CompiledCode(CompilerDriver* compiler_driver, InstructionSet instruction_set, - const std::vector& quick_code); + const ArrayRef& quick_code); InstructionSet GetInstructionSet() const { return instruction_set_; } - const std::vector* GetQuickCode() const { + const SwapVector* GetQuickCode() const { return quick_code_; } - void SetCode(const std::vector* quick_code); + void SetCode(const ArrayRef* quick_code); bool operator==(const CompiledCode& rhs) const; @@ -78,7 +79,7 @@ class CompiledCode { const InstructionSet instruction_set_; // Used to store the PIC code for Quick. - std::vector* quick_code_; + SwapVector* quick_code_; // There are offsets from the oatdata symbol to where the offset to // the compiled method will be found. These are computed by the @@ -109,8 +110,23 @@ class SrcMapElem { } }; -class SrcMap FINAL : public std::vector { +template +class SrcMap FINAL : public std::vector { public: + using std::vector::begin; + using typename std::vector::const_iterator; + using std::vector::empty; + using std::vector::end; + using std::vector::resize; + using std::vector::shrink_to_fit; + using std::vector::size; + + explicit SrcMap() {} + + template + SrcMap(InputIt first, InputIt last, const Allocator& alloc) + : std::vector(first, last, alloc) {} + void SortByFrom() { std::sort(begin(), end(), [] (const SrcMapElem& lhs, const SrcMapElem& rhs) -> bool { return lhs.from_ < rhs.from_; @@ -158,6 +174,10 @@ class SrcMap FINAL : public std::vector { } }; +using DefaultSrcMap = SrcMap>; +using SwapSrcMap = SrcMap>; + + enum LinkerPatchType { kLinkerPatchMethod, kLinkerPatchCall, @@ -255,40 +275,57 @@ inline bool operator<(const LinkerPatch& lhs, const LinkerPatch& rhs) { class CompiledMethod FINAL : public CompiledCode { public: - // Constructs a CompiledMethod for Quick. + // Constructs a CompiledMethod. + // Note: Consider using the static allocation methods below that will allocate the CompiledMethod + // in the swap space. CompiledMethod(CompilerDriver* driver, InstructionSet instruction_set, - const std::vector& quick_code, + const ArrayRef& quick_code, const size_t frame_size_in_bytes, const uint32_t core_spill_mask, const uint32_t fp_spill_mask, - SrcMap* src_mapping_table, - const std::vector& mapping_table, - const std::vector& vmap_table, - const std::vector& native_gc_map, - const std::vector* cfi_info, + DefaultSrcMap* src_mapping_table, + const ArrayRef& mapping_table, + const ArrayRef& vmap_table, + const ArrayRef& native_gc_map, + const ArrayRef& cfi_info, const ArrayRef& patches = ArrayRef()); - // Constructs a CompiledMethod for Optimizing. - CompiledMethod(CompilerDriver* driver, - InstructionSet instruction_set, - const std::vector& quick_code, - const size_t frame_size_in_bytes, - const uint32_t core_spill_mask, - const uint32_t fp_spill_mask, - const std::vector& vmap_table); - - // Constructs a CompiledMethod for the QuickJniCompiler. - CompiledMethod(CompilerDriver* driver, - InstructionSet instruction_set, - const std::vector& quick_code, - const size_t frame_size_in_bytes, - const uint32_t core_spill_mask, - const uint32_t fp_spill_mask, - const std::vector* cfi_info); - ~CompiledMethod() {} + static CompiledMethod* SwapAllocCompiledMethod( + CompilerDriver* driver, + InstructionSet instruction_set, + const ArrayRef& quick_code, + const size_t frame_size_in_bytes, + const uint32_t core_spill_mask, + const uint32_t fp_spill_mask, + DefaultSrcMap* src_mapping_table, + const ArrayRef& mapping_table, + const ArrayRef& vmap_table, + const ArrayRef& native_gc_map, + const ArrayRef& cfi_info, + const ArrayRef& patches = ArrayRef()); + + static CompiledMethod* SwapAllocCompiledMethodStackMap( + CompilerDriver* driver, + InstructionSet instruction_set, + const ArrayRef& quick_code, + const size_t frame_size_in_bytes, + const uint32_t core_spill_mask, + const uint32_t fp_spill_mask, + const ArrayRef& stack_map); + + static CompiledMethod* SwapAllocCompiledMethodCFI(CompilerDriver* driver, + InstructionSet instruction_set, + const ArrayRef& quick_code, + const size_t frame_size_in_bytes, + const uint32_t core_spill_mask, + const uint32_t fp_spill_mask, + const ArrayRef& cfi_info); + + static void ReleaseSwapAllocatedCompiledMethod(CompilerDriver* driver, CompiledMethod* m); + size_t GetFrameSizeInBytes() const { return frame_size_in_bytes_; } @@ -301,29 +338,29 @@ class CompiledMethod FINAL : public CompiledCode { return fp_spill_mask_; } - const SrcMap& GetSrcMappingTable() const { + const SwapSrcMap& GetSrcMappingTable() const { DCHECK(src_mapping_table_ != nullptr); return *src_mapping_table_; } - std::vector const* GetMappingTable() const { + SwapVector const* GetMappingTable() const { return mapping_table_; } - const std::vector& GetVmapTable() const { + const SwapVector& GetVmapTable() const { DCHECK(vmap_table_ != nullptr); return *vmap_table_; } - std::vector const* GetGcMap() const { + SwapVector const* GetGcMap() const { return gc_map_; } - const std::vector* GetCFIInfo() const { + const SwapVector* GetCFIInfo() const { return cfi_info_; } - const std::vector& GetPatches() const { + const SwapVector& GetPatches() const { return patches_; } @@ -335,19 +372,19 @@ class CompiledMethod FINAL : public CompiledCode { // For quick code, a bit mask describing spilled FPR callee-save registers. const uint32_t fp_spill_mask_; // For quick code, a set of pairs (PC, Line) mapping from native PC offset to Java line - SrcMap* src_mapping_table_; + SwapSrcMap* src_mapping_table_; // For quick code, a uleb128 encoded map from native PC offset to dex PC aswell as dex PC to // native PC offset. Size prefixed. - std::vector* mapping_table_; + SwapVector* mapping_table_; // For quick code, a uleb128 encoded map from GPR/FPR register to dex register. Size prefixed. - std::vector* vmap_table_; + SwapVector* vmap_table_; // For quick code, a map keyed by native PC indices to bitmaps describing what dalvik registers // are live. - std::vector* gc_map_; + SwapVector* gc_map_; // For quick code, a FDE entry for the debug_frame section. - std::vector* cfi_info_; + SwapVector* cfi_info_; // For quick code, linker patches needed by the method. - std::vector patches_; + SwapVector patches_; }; } // namespace art -- cgit v1.2.3-59-g8ed1b