707 // ReallocMark, which is declared in the same scope as the reallocated
708 // pointer. Any operation that could __potentially__ cause a reallocation
709 // should check the ReallocMark.
710 class ReallocMark: public StackObj {
711 protected:
712 NOT_PRODUCT(int _nesting;)
713
714 public:
715 ReallocMark() PRODUCT_RETURN;
716 void check() PRODUCT_RETURN;
717 };
718
719 // Helper class to allocate arrays that may become large.
720 // Uses the OS malloc for allocations smaller than ArrayAllocatorMallocLimit
721 // and uses mapped memory for larger allocations.
722 // Most OS mallocs do something similar but Solaris malloc does not revert
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
725 // limit to get mapped memory.
726 template <class E, MEMFLAGS F>
727 class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
728 char* _addr;
729 bool _use_malloc;
730 size_t _size;
731 bool _free_in_destructor;
732
733 static bool should_use_malloc(size_t size) {
734 return size < ArrayAllocatorMallocLimit;
735 }
736
737 static char* allocate_inner(size_t& size, bool& use_malloc);
738 public:
739 ArrayAllocator(bool free_in_destructor = true) :
740 _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
741
742 ~ArrayAllocator() {
743 if (_free_in_destructor) {
744 free();
745 }
746 }
747
748 E* allocate(size_t length);
749 E* reallocate(size_t new_length);
750 void free();
751 };
752
753 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP
|
707 // ReallocMark, which is declared in the same scope as the reallocated
708 // pointer. Any operation that could __potentially__ cause a reallocation
709 // should check the ReallocMark.
710 class ReallocMark: public StackObj {
711 protected:
712 NOT_PRODUCT(int _nesting;)
713
714 public:
715 ReallocMark() PRODUCT_RETURN;
716 void check() PRODUCT_RETURN;
717 };
718
719 // Helper class to allocate arrays that may become large.
720 // Uses the OS malloc for allocations smaller than ArrayAllocatorMallocLimit
721 // and uses mapped memory for larger allocations.
722 // Most OS mallocs do something similar but Solaris malloc does not revert
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
725 // limit to get mapped memory.
726 template <class E, MEMFLAGS F>
727 class ArrayAllocator : public AllStatic {
728 private:
729 static bool should_use_malloc(size_t length) {
730 return length * sizeof(E) < ArrayAllocatorMallocLimit;
731 }
732
733 static size_t size_for_malloc(size_t length);
734 static size_t size_for_mmap(size_t length);
735
736 static E* allocate_malloc(size_t length);
737 static E* allocate_mmap(size_t length);
738
739 static void free_malloc(E* addr, size_t length);
740 static void free_mmap(E* addr, size_t length);
741
742 public:
743 static E* allocate(size_t length);
744 static E* reallocate(E* old_addr, size_t old_length, size_t new_length);
745 static void free(E* addr, size_t length);
746 };
747
748 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP
|