< prev index next >

src/share/vm/memory/allocation.hpp

Print this page
rev 10379 : 8151436: Leaner ArrayAllocator

@@ -722,32 +722,27 @@
 // Most OS mallocs do something similar but Solaris malloc does not revert
 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
 // is set so that we always use malloc except for Solaris where we set the
 // limit to get mapped memory.
 template <class E, MEMFLAGS F>
-class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
-  char* _addr;
-  bool _use_malloc;
-  size_t _size;
-  bool _free_in_destructor;
-
-  static bool should_use_malloc(size_t size) {
-    return size < ArrayAllocatorMallocLimit;
+class ArrayAllocator : public AllStatic {
+ private:
+  static bool should_use_malloc(size_t length) {
+    return length * sizeof(E) < ArrayAllocatorMallocLimit;
   }
 
-  static char* allocate_inner(size_t& size, bool& use_malloc);
- public:
-  ArrayAllocator(bool free_in_destructor = true) :
-    _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
+  static size_t size_for_malloc(size_t length);
+  static size_t size_for_mmap(size_t length);
 
-  ~ArrayAllocator() {
-    if (_free_in_destructor) {
-      free();
-    }
-  }
+  static E* allocate_malloc(size_t length);
+  static E* allocate_mmap(size_t length);
+
+  static void free_malloc(E* addr, size_t length);
+  static void free_mmap(E* addr, size_t length);
 
-  E* allocate(size_t length);
-  E* reallocate(size_t new_length);
-  void free();
+ public:
+  static E* allocate(size_t length);
+  static E* reallocate(E* old_addr, size_t old_length, size_t new_length);
+  static void free(E* addr, size_t length);
 };
 
 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP
< prev index next >