hotspot/src/share/vm/memory/allocation.hpp
changeset 37057 03b3e1870228
parent 33097 96e348cb0442
child 37092 0e56e3c9d545
equal deleted inserted replaced
37056:109f610020fa 37057:03b3e1870228
   722 // Most OS mallocs do something similar but Solaris malloc does not revert
   722 // Most OS mallocs do something similar but Solaris malloc does not revert
   723 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
   723 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
   724 // is set so that we always use malloc except for Solaris where we set the
   724 // is set so that we always use malloc except for Solaris where we set the
   725 // limit to get mapped memory.
   725 // limit to get mapped memory.
   726 template <class E, MEMFLAGS F>
   726 template <class E, MEMFLAGS F>
   727 class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
   727 class ArrayAllocator : public AllStatic {
   728   char* _addr;
   728  private:
   729   bool _use_malloc;
   729   static bool should_use_malloc(size_t length);
   730   size_t _size;
   730 
   731   bool _free_in_destructor;
   731   static size_t size_for_malloc(size_t length);
   732 
   732   static size_t size_for_mmap(size_t length);
   733   static bool should_use_malloc(size_t size) {
   733 
   734     return size < ArrayAllocatorMallocLimit;
   734   static E* allocate_malloc(size_t length);
   735   }
   735   static E* allocate_mmap(size_t length);
   736 
   736 
   737   static char* allocate_inner(size_t& size, bool& use_malloc);
   737   static void free_malloc(E* addr, size_t length);
   738  public:
   738   static void free_mmap(E* addr, size_t length);
   739   ArrayAllocator(bool free_in_destructor = true) :
   739 
   740     _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
   740  public:
   741 
   741   static E* allocate(size_t length);
   742   ~ArrayAllocator() {
   742   static E* reallocate(E* old_addr, size_t old_length, size_t new_length);
   743     if (_free_in_destructor) {
   743   static void free(E* addr, size_t length);
   744       free();
       
   745     }
       
   746   }
       
   747 
       
   748   E* allocate(size_t length);
       
   749   E* reallocate(size_t new_length);
       
   750   void free();
       
   751 };
   744 };
   752 
   745 
   753 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP
   746 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP