src/share/vm/memory/allocation.inline.hpp
Print this page
rev 4523 : 7197666: java -d64 -version core dumps in a box with lots of memory
Summary: Allow task queues to be mmapped instead of malloced on Solaris
Reviewed-by: coleenp, jmasa, johnc, tschatzl
@@ -101,7 +101,51 @@
template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){
FreeHeap(p, F);
}
+template <class E, MEMFLAGS F>
+E* ArrayAllocator<E, F>::allocate(size_t length) {
+ assert(_addr == NULL, "Already in use");
+ _size = sizeof(E) * length;
+ _use_malloc = _size < ArrayAllocatorMallocLimit;
+
+ if (_use_malloc) {
+ _addr = AllocateHeap(_size, F);
+ if (_addr == NULL && _size >= (size_t)os::vm_allocation_granularity()) {
+ // malloc failed let's try with mmap instead
+ _use_malloc = false;
+ } else {
+ return (E*)_addr;
+ }
+ }
+
+ int alignment = os::vm_allocation_granularity();
+ _size = align_size_up(_size, alignment);
+
+ _addr = os::reserve_memory(_size, NULL, alignment, F);
+ if (_addr == NULL) {
+ vm_exit_out_of_memory(_size, "Allocator (reserve)");
+ }
+
+ bool success = os::commit_memory(_addr, _size, false /* executable */);
+ if (!success) {
+ vm_exit_out_of_memory(_size, "Allocator (commit)");
+ }
+
+ return (E*)_addr;
+}
+
+template<class E, MEMFLAGS F>
+void ArrayAllocator<E, F>::free() {
+ if (_addr != NULL) {
+ if (_use_malloc) {
+ FreeHeap(_addr, F);
+ } else {
+ os::release_memory(_addr, _size);
+ }
+ _addr = NULL;
+ }
+}
+
#endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP