J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
David Holmes | 5f1f448 | 2016-08-21 20:56:37 -0400 | [diff] [blame] | 2 | * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
Erik Trimble | ba7c173 | 2010-05-27 19:08:38 -0700 | [diff] [blame] | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
Stefan Karlsson | 8006fe8 | 2010-11-23 13:22:55 -0800 | [diff] [blame] | 25 | #ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |
| 26 | #define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |
| 27 | |
David Holmes | 5f1f448 | 2016-08-21 20:56:37 -0400 | [diff] [blame] | 28 | #include "runtime/atomic.hpp" |
Stefan Karlsson | 8006fe8 | 2010-11-23 13:22:55 -0800 | [diff] [blame] | 29 | #include "runtime/os.hpp" |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 30 | #include "services/memTracker.hpp" |
Stefan Karlsson | a18f1c2 | 2017-07-05 11:33:17 +0200 | [diff] [blame] | 31 | #include "utilities/align.hpp" |
Yasumasa Suenaga | 161976b | 2016-06-21 19:29:39 -0400 | [diff] [blame] | 32 | #include "utilities/globalDefinitions.hpp" |
Stefan Karlsson | 8006fe8 | 2010-11-23 13:22:55 -0800 | [diff] [blame] | 33 | |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 34 | // Explicit C-heap memory management |
| 35 | |
| 36 | void trace_heap_malloc(size_t size, const char* name, void *p); |
| 37 | void trace_heap_free(void *p); |
| 38 | |
Vladimir Kozlov | c130620 | 2011-02-10 19:34:48 -0800 | [diff] [blame] | 39 | #ifndef PRODUCT |
Vladimir Kozlov | b9633d4 | 2011-02-07 10:34:39 -0800 | [diff] [blame] | 40 | // Increments unsigned long value for statistics (not atomic on MP). |
| 41 | inline void inc_stat_counter(volatile julong* dest, julong add_value) { |
Vladimir Kozlov | c130620 | 2011-02-10 19:34:48 -0800 | [diff] [blame] | 42 | #if defined(SPARC) || defined(X86) |
| 43 | // Sparc and X86 have atomic jlong (8 bytes) instructions |
Vladimir Kozlov | b9633d4 | 2011-02-07 10:34:39 -0800 | [diff] [blame] | 44 | julong value = Atomic::load((volatile jlong*)dest); |
| 45 | value += add_value; |
| 46 | Atomic::store((jlong)value, (volatile jlong*)dest); |
Vladimir Kozlov | c130620 | 2011-02-10 19:34:48 -0800 | [diff] [blame] | 47 | #else |
| 48 | // possible word-tearing during load/store |
| 49 | *dest += add_value; |
| 50 | #endif |
Vladimir Kozlov | b9633d4 | 2011-02-07 10:34:39 -0800 | [diff] [blame] | 51 | } |
Vladimir Kozlov | c130620 | 2011-02-10 19:34:48 -0800 | [diff] [blame] | 52 | #endif |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 53 | |
| 54 | // allocate using malloc; will fail if no memory available |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 55 | inline char* AllocateHeap(size_t size, MEMFLAGS flags, |
| 56 | const NativeCallStack& stack, |
Nils Loodin | 953bec3 | 2012-10-17 17:36:48 +0200 | [diff] [blame] | 57 | AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 58 | char* p = (char*) os::malloc(size, flags, stack); |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 59 | #ifdef ASSERT |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 60 | if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p); |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 61 | #endif |
Calvin Cheung | 0f7adcc | 2013-04-30 11:56:52 -0700 | [diff] [blame] | 62 | if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
| 63 | vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap"); |
| 64 | } |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 65 | return p; |
| 66 | } |
Yasumasa Suenaga | 649f4e8 | 2015-04-28 19:04:39 +0900 | [diff] [blame] | 67 | |
Yasumasa Suenaga | 161976b | 2016-06-21 19:29:39 -0400 | [diff] [blame] | 68 | ALWAYSINLINE char* AllocateHeap(size_t size, MEMFLAGS flags, |
Nils Loodin | 953bec3 | 2012-10-17 17:36:48 +0200 | [diff] [blame] | 69 | AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 70 | return AllocateHeap(size, flags, CURRENT_PC, alloc_failmode); |
| 71 | } |
| 72 | |
Yasumasa Suenaga | 161976b | 2016-06-21 19:29:39 -0400 | [diff] [blame] | 73 | ALWAYSINLINE char* ReallocateHeap(char *old, size_t size, MEMFLAGS flag, |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 74 | AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
| 75 | char* p = (char*) os::realloc(old, size, flag, CURRENT_PC); |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 76 | #ifdef ASSERT |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 77 | if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p); |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 78 | #endif |
Calvin Cheung | 0f7adcc | 2013-04-30 11:56:52 -0700 | [diff] [blame] | 79 | if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
| 80 | vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap"); |
| 81 | } |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 82 | return p; |
| 83 | } |
| 84 | |
Max Ockner | 91dbd4f | 2014-12-01 12:16:15 -0500 | [diff] [blame] | 85 | inline void FreeHeap(void* p) { |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 86 | #ifdef ASSERT |
| 87 | if (PrintMallocFree) trace_heap_free(p); |
| 88 | #endif |
Max Ockner | 91dbd4f | 2014-12-01 12:16:15 -0500 | [diff] [blame] | 89 | os::free(p); |
J. Duke | 8153779 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 90 | } |
Stefan Karlsson | 8006fe8 | 2010-11-23 13:22:55 -0800 | [diff] [blame] | 91 | |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 92 | |
| 93 | template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size, |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 94 | const NativeCallStack& stack) throw() { |
| 95 | void* p = (void*)AllocateHeap(size, F, stack); |
| 96 | #ifdef ASSERT |
| 97 | if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); |
| 98 | #endif |
| 99 | return p; |
| 100 | } |
| 101 | |
| 102 | template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size) throw() { |
| 103 | return CHeapObj<F>::operator new(size, CALLER_PC); |
| 104 | } |
| 105 | |
| 106 | template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size, |
| 107 | const std::nothrow_t& nothrow_constant, const NativeCallStack& stack) throw() { |
| 108 | void* p = (void*)AllocateHeap(size, F, stack, |
| 109 | AllocFailStrategy::RETURN_NULL); |
Yumin Qi | 98151c3 | 2013-05-14 09:41:12 -0700 | [diff] [blame] | 110 | #ifdef ASSERT |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 111 | if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 112 | #endif |
Yumin Qi | 98151c3 | 2013-05-14 09:41:12 -0700 | [diff] [blame] | 113 | return p; |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size, |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 117 | const std::nothrow_t& nothrow_constant) throw() { |
| 118 | return CHeapObj<F>::operator new(size, nothrow_constant, CALLER_PC); |
Yumin Qi | 98151c3 | 2013-05-14 09:41:12 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size, |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 122 | const NativeCallStack& stack) throw() { |
| 123 | return CHeapObj<F>::operator new(size, stack); |
| 124 | } |
| 125 | |
| 126 | template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size) |
| 127 | throw() { |
| 128 | return CHeapObj<F>::operator new(size, CALLER_PC); |
Yumin Qi | 98151c3 | 2013-05-14 09:41:12 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size, |
Zhengyu Gu | f0cf82f | 2014-08-07 12:18:58 -0700 | [diff] [blame] | 132 | const std::nothrow_t& nothrow_constant, const NativeCallStack& stack) throw() { |
| 133 | return CHeapObj<F>::operator new(size, nothrow_constant, stack); |
| 134 | } |
| 135 | |
| 136 | template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size, |
| 137 | const std::nothrow_t& nothrow_constant) throw() { |
| 138 | return CHeapObj<F>::operator new(size, nothrow_constant, CALLER_PC); |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){ |
Max Ockner | 91dbd4f | 2014-12-01 12:16:15 -0500 | [diff] [blame] | 142 | FreeHeap(p); |
Yumin Qi | 98151c3 | 2013-05-14 09:41:12 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | template <MEMFLAGS F> void CHeapObj<F>::operator delete [](void* p){ |
Max Ockner | 91dbd4f | 2014-12-01 12:16:15 -0500 | [diff] [blame] | 146 | FreeHeap(p); |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 147 | } |
| 148 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 149 | template <class E> |
| 150 | size_t MmapArrayAllocator<E>::size_for(size_t length) { |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 151 | size_t size = length * sizeof(E); |
Bengt Rutisson | 4a685f1 | 2013-04-08 07:49:28 +0200 | [diff] [blame] | 152 | int alignment = os::vm_allocation_granularity(); |
Stefan Karlsson | dbd3b5a | 2017-07-04 15:58:10 +0200 | [diff] [blame] | 153 | return align_up(size, alignment); |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 154 | } |
Bengt Rutisson | 4a685f1 | 2013-04-08 07:49:28 +0200 | [diff] [blame] | 155 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 156 | template <class E> |
| 157 | E* MmapArrayAllocator<E>::allocate_or_null(size_t length, MEMFLAGS flags) { |
Thomas Schatzl | 94bbcbd | 2016-09-15 16:44:19 +0200 | [diff] [blame] | 158 | size_t size = size_for(length); |
| 159 | int alignment = os::vm_allocation_granularity(); |
| 160 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 161 | char* addr = os::reserve_memory(size, NULL, alignment, flags); |
Thomas Schatzl | 94bbcbd | 2016-09-15 16:44:19 +0200 | [diff] [blame] | 162 | if (addr == NULL) { |
| 163 | return NULL; |
| 164 | } |
| 165 | |
| 166 | if (os::commit_memory(addr, size, !ExecMem, "Allocator (commit)")) { |
| 167 | return (E*)addr; |
| 168 | } else { |
| 169 | os::release_memory(addr, size); |
| 170 | return NULL; |
| 171 | } |
| 172 | } |
| 173 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 174 | template <class E> |
| 175 | E* MmapArrayAllocator<E>::allocate(size_t length, MEMFLAGS flags) { |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 176 | size_t size = size_for(length); |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 177 | int alignment = os::vm_allocation_granularity(); |
| 178 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 179 | char* addr = os::reserve_memory(size, NULL, alignment, flags); |
Mikael Gerdin | a52fd33 | 2014-04-02 14:17:34 +0200 | [diff] [blame] | 180 | if (addr == NULL) { |
| 181 | vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "Allocator (reserve)"); |
Bengt Rutisson | 4a685f1 | 2013-04-08 07:49:28 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Mikael Gerdin | a52fd33 | 2014-04-02 14:17:34 +0200 | [diff] [blame] | 184 | os::commit_memory_or_exit(addr, size, !ExecMem, "Allocator (commit)"); |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 185 | |
| 186 | return (E*)addr; |
Mikael Gerdin | a52fd33 | 2014-04-02 14:17:34 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 189 | template <class E> |
| 190 | void MmapArrayAllocator<E>::free(E* addr, size_t length) { |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 191 | bool result = os::release_memory((char*)addr, size_for(length)); |
| 192 | assert(result, "Failed to release memory"); |
| 193 | } |
| 194 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 195 | template <class E> |
| 196 | size_t MallocArrayAllocator<E>::size_for(size_t length) { |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 197 | return length * sizeof(E); |
| 198 | } |
| 199 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 200 | template <class E> |
| 201 | E* MallocArrayAllocator<E>::allocate(size_t length, MEMFLAGS flags) { |
| 202 | return (E*)AllocateHeap(size_for(length), flags); |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 205 | template<class E> |
| 206 | void MallocArrayAllocator<E>::free(E* addr, size_t /*length*/) { |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 207 | FreeHeap(addr); |
| 208 | } |
| 209 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 210 | template <class E> |
| 211 | bool ArrayAllocator<E>::should_use_malloc(size_t length) { |
| 212 | return MallocArrayAllocator<E>::size_for(length) < ArrayAllocatorMallocLimit; |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 213 | } |
| 214 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 215 | template <class E> |
| 216 | E* ArrayAllocator<E>::allocate_malloc(size_t length, MEMFLAGS flags) { |
| 217 | return MallocArrayAllocator<E>::allocate(length, flags); |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 220 | template <class E> |
| 221 | E* ArrayAllocator<E>::allocate_mmap(size_t length, MEMFLAGS flags) { |
| 222 | return MmapArrayAllocator<E>::allocate(length, flags); |
Stefan Karlsson | 3fa2f0c | 2016-03-09 17:03:04 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 225 | template <class E> |
| 226 | E* ArrayAllocator<E>::allocate(size_t length, MEMFLAGS flags) { |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 227 | if (should_use_malloc(length)) { |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 228 | return allocate_malloc(length, flags); |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 229 | } |
Mikael Gerdin | a52fd33 | 2014-04-02 14:17:34 +0200 | [diff] [blame] | 230 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 231 | return allocate_mmap(length, flags); |
Bengt Rutisson | 4a685f1 | 2013-04-08 07:49:28 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 234 | template <class E> |
| 235 | E* ArrayAllocator<E>::reallocate(E* old_addr, size_t old_length, size_t new_length, MEMFLAGS flags) { |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 236 | E* new_addr = (new_length > 0) |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 237 | ? allocate(new_length, flags) |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 238 | : NULL; |
Mikael Gerdin | a52fd33 | 2014-04-02 14:17:34 +0200 | [diff] [blame] | 239 | |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 240 | if (new_addr != NULL && old_addr != NULL) { |
| 241 | memcpy(new_addr, old_addr, MIN2(old_length, new_length) * sizeof(E)); |
| 242 | } |
Mikael Gerdin | a52fd33 | 2014-04-02 14:17:34 +0200 | [diff] [blame] | 243 | |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 244 | if (old_addr != NULL) { |
| 245 | free(old_addr, old_length); |
| 246 | } |
| 247 | |
| 248 | return new_addr; |
Mikael Gerdin | a52fd33 | 2014-04-02 14:17:34 +0200 | [diff] [blame] | 249 | } |
| 250 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 251 | template<class E> |
| 252 | void ArrayAllocator<E>::free_malloc(E* addr, size_t length) { |
| 253 | MallocArrayAllocator<E>::free(addr, length); |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 254 | } |
| 255 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 256 | template<class E> |
| 257 | void ArrayAllocator<E>::free_mmap(E* addr, size_t length) { |
| 258 | MmapArrayAllocator<E>::free(addr, length); |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Milan Mimica | f647f78 | 2017-07-21 21:01:59 -0400 | [diff] [blame] | 261 | template<class E> |
| 262 | void ArrayAllocator<E>::free(E* addr, size_t length) { |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 263 | if (addr != NULL) { |
| 264 | if (should_use_malloc(length)) { |
| 265 | free_malloc(addr, length); |
Bengt Rutisson | 4a685f1 | 2013-04-08 07:49:28 +0200 | [diff] [blame] | 266 | } else { |
Stefan Karlsson | 7419b91 | 2016-03-09 12:44:12 +0100 | [diff] [blame] | 267 | free_mmap(addr, length); |
Bengt Rutisson | 4a685f1 | 2013-04-08 07:49:28 +0200 | [diff] [blame] | 268 | } |
Bengt Rutisson | 4a685f1 | 2013-04-08 07:49:28 +0200 | [diff] [blame] | 269 | } |
| 270 | } |
Zhengyu Gu | a39b176 | 2012-06-28 17:03:16 -0400 | [diff] [blame] | 271 | |
Stefan Karlsson | 8006fe8 | 2010-11-23 13:22:55 -0800 | [diff] [blame] | 272 | #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |