src/share/vm/memory/allocation.inline.hpp

Print this page




 129   _use_malloc = _size < ArrayAllocatorMallocLimit;
 130 
 131   if (_use_malloc) {
 132     _addr = AllocateHeap(_size, F);
 133     if (_addr == NULL && _size >=  (size_t)os::vm_allocation_granularity()) {
 134       // malloc failed let's try with mmap instead
 135       _use_malloc = false;
 136     } else {
 137       return (E*)_addr;
 138     }
 139   }
 140 
 141   int alignment = os::vm_allocation_granularity();
 142   _size = align_size_up(_size, alignment);
 143 
 144   _addr = os::reserve_memory(_size, NULL, alignment, F);
 145   if (_addr == NULL) {
 146     vm_exit_out_of_memory(_size, OOM_MMAP_ERROR, "Allocator (reserve)");
 147   }
 148 
 149   bool success = os::commit_memory(_addr, _size, false /* executable */);
 150   if (!success) {
 151     vm_exit_out_of_memory(_size, OOM_MMAP_ERROR, "Allocator (commit)");
 152   }
 153 
 154   return (E*)_addr;
 155 }
 156 
 157 template<class E, MEMFLAGS F>
 158 void ArrayAllocator<E, F>::free() {
 159   if (_addr != NULL) {
 160     if (_use_malloc) {
 161       FreeHeap(_addr, F);
 162     } else {
 163       os::release_memory(_addr, _size);
 164     }
 165     _addr = NULL;
 166   }
 167 }
 168 
 169 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP


 129   _use_malloc = _size < ArrayAllocatorMallocLimit;
 130 
 131   if (_use_malloc) {
 132     _addr = AllocateHeap(_size, F);
 133     if (_addr == NULL && _size >=  (size_t)os::vm_allocation_granularity()) {
 134       // malloc failed let's try with mmap instead
 135       _use_malloc = false;
 136     } else {
 137       return (E*)_addr;
 138     }
 139   }
 140 
 141   int alignment = os::vm_allocation_granularity();
 142   _size = align_size_up(_size, alignment);
 143 
 144   _addr = os::reserve_memory(_size, NULL, alignment, F);
 145   if (_addr == NULL) {
 146     vm_exit_out_of_memory(_size, OOM_MMAP_ERROR, "Allocator (reserve)");
 147   }
 148 
 149   os::commit_memory_or_exit(_addr, _size, !ExecMem, "Allocator (commit)");



 150 
 151   return (E*)_addr;
 152 }
 153 
 154 template<class E, MEMFLAGS F>
 155 void ArrayAllocator<E, F>::free() {
 156   if (_addr != NULL) {
 157     if (_use_malloc) {
 158       FreeHeap(_addr, F);
 159     } else {
 160       os::release_memory(_addr, _size);
 161     }
 162     _addr = NULL;
 163   }
 164 }
 165 
 166 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP