src/share/vm/memory/allocation.inline.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/memory

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

Print this page




 111 template <class E, MEMFLAGS F>
 112 E* ArrayAllocator<E, F>::allocate(size_t length) {
 113   assert(_addr == NULL, "Already in use");
 114 
 115   _size = sizeof(E) * length;
 116   _use_malloc = _size < ArrayAllocatorMallocLimit;
 117 
 118   if (_use_malloc) {
 119     _addr = AllocateHeap(_size, F);
 120     if (_addr == NULL && _size >=  (size_t)os::vm_allocation_granularity()) {
 121       // malloc failed let's try with mmap instead
 122       _use_malloc = false;
 123     } else {
 124       return (E*)_addr;
 125     }
 126   }
 127 
 128   int alignment = os::vm_allocation_granularity();
 129   _size = align_size_up(_size, alignment);
 130 
 131   _addr = os::reserve_memory(_size, NULL, alignment);
 132   if (_addr == NULL) {
 133     vm_exit_out_of_memory(_size, "Allocator (reserve)");
 134   }
 135 
 136   bool success = os::commit_memory(_addr, _size, false /* executable */);
 137   if (!success) {
 138     vm_exit_out_of_memory(_size, "Allocator (commit)");
 139   }
 140 
 141   return (E*)_addr;
 142 }
 143 
 144 template<class E, MEMFLAGS F>
 145 void ArrayAllocator<E, F>::free() {
 146   if (_addr != NULL) {
 147     if (_use_malloc) {
 148       FreeHeap(_addr, F);
 149     } else {
 150       os::release_memory(_addr, _size);
 151     }


 111 template <class E, MEMFLAGS F>
 112 E* ArrayAllocator<E, F>::allocate(size_t length) {
 113   assert(_addr == NULL, "Already in use");
 114 
 115   _size = sizeof(E) * length;
 116   _use_malloc = _size < ArrayAllocatorMallocLimit;
 117 
 118   if (_use_malloc) {
 119     _addr = AllocateHeap(_size, F);
 120     if (_addr == NULL && _size >=  (size_t)os::vm_allocation_granularity()) {
 121       // malloc failed let's try with mmap instead
 122       _use_malloc = false;
 123     } else {
 124       return (E*)_addr;
 125     }
 126   }
 127 
 128   int alignment = os::vm_allocation_granularity();
 129   _size = align_size_up(_size, alignment);
 130 
 131   _addr = os::reserve_memory(_size, NULL, alignment, F);
 132   if (_addr == NULL) {
 133     vm_exit_out_of_memory(_size, "Allocator (reserve)");
 134   }
 135 
 136   bool success = os::commit_memory(_addr, _size, false /* executable */);
 137   if (!success) {
 138     vm_exit_out_of_memory(_size, "Allocator (commit)");
 139   }
 140 
 141   return (E*)_addr;
 142 }
 143 
 144 template<class E, MEMFLAGS F>
 145 void ArrayAllocator<E, F>::free() {
 146   if (_addr != NULL) {
 147     if (_use_malloc) {
 148       FreeHeap(_addr, F);
 149     } else {
 150       os::release_memory(_addr, _size);
 151     }
src/share/vm/memory/allocation.inline.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File