src/share/vm/memory/allocation.hpp

Print this page
rev 6170 : 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
Summary: Add reallocate functionality to ArrayAllocator and use it from BitMap::resize
Reviewed-by:


 731   NOT_PRODUCT(int _nesting;)
 732 
 733 public:
 734   ReallocMark()   PRODUCT_RETURN;
 735   void check()    PRODUCT_RETURN;
 736 };
 737 
 738 // Helper class to allocate arrays that may become large.
 739 // Uses the OS malloc for allocations smaller than ArrayAllocatorMallocLimit
 740 // and uses mapped memory for larger allocations.
 741 // Most OS mallocs do something similar but Solaris malloc does not revert
 742 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
 743 // is set so that we always use malloc except for Solaris where we set the
 744 // limit to get mapped memory.
 745 template <class E, MEMFLAGS F>
 746 class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
 747   char* _addr;
 748   bool _use_malloc;
 749   size_t _size;
 750   bool _free_in_destructor;






 751  public:
 752   ArrayAllocator(bool free_in_destructor = true) :
 753     _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
 754 
 755   ~ArrayAllocator() {
 756     if (_free_in_destructor) {
 757       free();
 758     }
 759   }
 760 
 761   E* allocate(size_t length);

 762   void free();
 763 };
 764 
 765 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP


 731   NOT_PRODUCT(int _nesting;)
 732 
 733 public:
 734   ReallocMark()   PRODUCT_RETURN;
 735   void check()    PRODUCT_RETURN;
 736 };
 737 
 738 // Helper class to allocate arrays that may become large.
 739 // Uses the OS malloc for allocations smaller than ArrayAllocatorMallocLimit
 740 // and uses mapped memory for larger allocations.
 741 // Most OS mallocs do something similar but Solaris malloc does not revert
 742 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
 743 // is set so that we always use malloc except for Solaris where we set the
 744 // limit to get mapped memory.
 745 template <class E, MEMFLAGS F>
 746 class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
 747   char* _addr;
 748   bool _use_malloc;
 749   size_t _size;
 750   bool _free_in_destructor;
 751 
 752   static bool should_use_malloc(size_t size) {
 753     return size < ArrayAllocatorMallocLimit;
 754   }
 755 
 756   static char* allocate_inner(size_t& size, bool& use_malloc);
 757  public:
 758   ArrayAllocator(bool free_in_destructor = true) :
 759     _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
 760 
 761   ~ArrayAllocator() {
 762     if (_free_in_destructor) {
 763       free();
 764     }
 765   }
 766 
 767   E* allocate(size_t length);
 768   E* reallocate(size_t new_length);
 769   void free();
 770 };
 771 
 772 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP