author | ysuenaga |
Wed, 18 Oct 2017 18:49:54 -0400 | |
changeset 47654 | dbd1f4f276ba |
parent 47216 | 71c04702a3d5 |
child 48532 | a53f30471b2d |
permissions | -rw-r--r-- |
1 | 1 |
/* |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39405
diff
changeset
|
2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |
26 |
#define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |
|
27 |
||
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39405
diff
changeset
|
28 |
#include "runtime/atomic.hpp" |
7397 | 29 |
#include "runtime/os.hpp" |
25946 | 30 |
#include "services/memTracker.hpp" |
46625 | 31 |
#include "utilities/align.hpp" |
39405
314741ca98d5
8153743: AllocateHeap() and ReallocateHeap() should use ALWAYSINLINE macro
ysuenaga
parents:
37096
diff
changeset
|
32 |
#include "utilities/globalDefinitions.hpp" |
7397 | 33 |
|
1 | 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 |
||
8325 | 39 |
#ifndef PRODUCT |
8320 | 40 |
// Increments unsigned long value for statistics (not atomic on MP). |
41 |
inline void inc_stat_counter(volatile julong* dest, julong add_value) { |
|
8325 | 42 |
#if defined(SPARC) || defined(X86) |
43 |
// Sparc and X86 have atomic jlong (8 bytes) instructions |
|
8320 | 44 |
julong value = Atomic::load((volatile jlong*)dest); |
45 |
value += add_value; |
|
46 |
Atomic::store((jlong)value, (volatile jlong*)dest); |
|
8325 | 47 |
#else |
48 |
// possible word-tearing during load/store |
|
49 |
*dest += add_value; |
|
50 |
#endif |
|
8320 | 51 |
} |
8325 | 52 |
#endif |
1 | 53 |
|
54 |
// allocate using malloc; will fail if no memory available |
|
25946 | 55 |
inline char* AllocateHeap(size_t size, MEMFLAGS flags, |
56 |
const NativeCallStack& stack, |
|
14083
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13963
diff
changeset
|
57 |
AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
25946 | 58 |
char* p = (char*) os::malloc(size, flags, stack); |
1 | 59 |
#ifdef ASSERT |
13195 | 60 |
if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p); |
1 | 61 |
#endif |
17087
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
62 |
if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
63 |
vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap"); |
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
64 |
} |
13195 | 65 |
return p; |
66 |
} |
|
30293
2bb164446d67
8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents:
27880
diff
changeset
|
67 |
|
39405
314741ca98d5
8153743: AllocateHeap() and ReallocateHeap() should use ALWAYSINLINE macro
ysuenaga
parents:
37096
diff
changeset
|
68 |
ALWAYSINLINE char* AllocateHeap(size_t size, MEMFLAGS flags, |
25946 | 69 |
AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
70 |
return AllocateHeap(size, flags, CURRENT_PC, alloc_failmode); |
|
71 |
} |
|
13195 | 72 |
|
39405
314741ca98d5
8153743: AllocateHeap() and ReallocateHeap() should use ALWAYSINLINE macro
ysuenaga
parents:
37096
diff
changeset
|
73 |
ALWAYSINLINE char* ReallocateHeap(char *old, size_t size, MEMFLAGS flag, |
14083
103054a71a30
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
13963
diff
changeset
|
74 |
AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
25946 | 75 |
char* p = (char*) os::realloc(old, size, flag, CURRENT_PC); |
13195 | 76 |
#ifdef ASSERT |
77 |
if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p); |
|
78 |
#endif |
|
17087
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
79 |
if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
80 |
vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap"); |
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
17031
diff
changeset
|
81 |
} |
1 | 82 |
return p; |
83 |
} |
|
84 |
||
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25946
diff
changeset
|
85 |
inline void FreeHeap(void* p) { |
1 | 86 |
#ifdef ASSERT |
87 |
if (PrintMallocFree) trace_heap_free(p); |
|
88 |
#endif |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25946
diff
changeset
|
89 |
os::free(p); |
1 | 90 |
} |
7397 | 91 |
|
13195 | 92 |
|
93 |
template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size, |
|
25946 | 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); |
|
17031 | 110 |
#ifdef ASSERT |
13195 | 111 |
if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
112 |
#endif |
17031 | 113 |
return p; |
13195 | 114 |
} |
115 |
||
116 |
template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size, |
|
25946 | 117 |
const std::nothrow_t& nothrow_constant) throw() { |
118 |
return CHeapObj<F>::operator new(size, nothrow_constant, CALLER_PC); |
|
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
119 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
120 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
121 |
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size, |
25946 | 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); |
|
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
129 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
130 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
131 |
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size, |
25946 | 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); |
|
13195 | 139 |
} |
140 |
||
141 |
template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){ |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25946
diff
changeset
|
142 |
FreeHeap(p); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
143 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
144 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
17302
diff
changeset
|
145 |
template <MEMFLAGS F> void CHeapObj<F>::operator delete [](void* p){ |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25946
diff
changeset
|
146 |
FreeHeap(p); |
13195 | 147 |
} |
148 |
||
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
149 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
150 |
size_t MmapArrayAllocator<E>::size_for(size_t length) { |
37057 | 151 |
size_t size = length * sizeof(E); |
152 |
int alignment = os::vm_allocation_granularity(); |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
41176
diff
changeset
|
153 |
return align_up(size, alignment); |
37057 | 154 |
} |
23545
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
155 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
156 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
157 |
E* MmapArrayAllocator<E>::allocate_or_null(size_t length, MEMFLAGS flags) { |
41176
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
158 |
size_t size = size_for(length); |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
159 |
int alignment = os::vm_allocation_granularity(); |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
160 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
161 |
char* addr = os::reserve_memory(size, NULL, alignment, flags); |
41176
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
162 |
if (addr == NULL) { |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
163 |
return NULL; |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
164 |
} |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
165 |
|
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
166 |
if (os::commit_memory(addr, size, !ExecMem, "Allocator (commit)")) { |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
167 |
return (E*)addr; |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
168 |
} else { |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
169 |
os::release_memory(addr, size); |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
170 |
return NULL; |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
171 |
} |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
172 |
} |
ff9f64534cff
8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents:
40655
diff
changeset
|
173 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
174 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
175 |
E* MmapArrayAllocator<E>::allocate(size_t length, MEMFLAGS flags) { |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
176 |
size_t size = size_for(length); |
23545
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
177 |
int alignment = os::vm_allocation_granularity(); |
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
178 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
179 |
char* addr = os::reserve_memory(size, NULL, alignment, flags); |
23545
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
180 |
if (addr == NULL) { |
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
181 |
vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "Allocator (reserve)"); |
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
182 |
} |
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
183 |
|
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
184 |
os::commit_memory_or_exit(addr, size, !ExecMem, "Allocator (commit)"); |
37057 | 185 |
|
186 |
return (E*)addr; |
|
23545
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
187 |
} |
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
188 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
189 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
190 |
void MmapArrayAllocator<E>::free(E* addr, size_t length) { |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
191 |
bool result = os::release_memory((char*)addr, size_for(length)); |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
192 |
assert(result, "Failed to release memory"); |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
193 |
} |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
194 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
195 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
196 |
size_t MallocArrayAllocator<E>::size_for(size_t length) { |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
197 |
return length * sizeof(E); |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
198 |
} |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
199 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
200 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
201 |
E* MallocArrayAllocator<E>::allocate(size_t length, MEMFLAGS flags) { |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
202 |
return (E*)AllocateHeap(size_for(length), flags); |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
203 |
} |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
204 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
205 |
template<class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
206 |
void MallocArrayAllocator<E>::free(E* addr, size_t /*length*/) { |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
207 |
FreeHeap(addr); |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
208 |
} |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
209 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
210 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
211 |
bool ArrayAllocator<E>::should_use_malloc(size_t length) { |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
212 |
return MallocArrayAllocator<E>::size_for(length) < ArrayAllocatorMallocLimit; |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
213 |
} |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
214 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
215 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
216 |
E* ArrayAllocator<E>::allocate_malloc(size_t length, MEMFLAGS flags) { |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
217 |
return MallocArrayAllocator<E>::allocate(length, flags); |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
218 |
} |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
219 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
220 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
221 |
E* ArrayAllocator<E>::allocate_mmap(size_t length, MEMFLAGS flags) { |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
222 |
return MmapArrayAllocator<E>::allocate(length, flags); |
37096
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
223 |
} |
42437cf54027
8151534: Refactor ArrayAllocator for easier reuse
stefank
parents:
37057
diff
changeset
|
224 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
225 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
226 |
E* ArrayAllocator<E>::allocate(size_t length, MEMFLAGS flags) { |
37057 | 227 |
if (should_use_malloc(length)) { |
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
228 |
return allocate_malloc(length, flags); |
37057 | 229 |
} |
16682
4e30a46f6b76
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
15855
diff
changeset
|
230 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
231 |
return allocate_mmap(length, flags); |
16682
4e30a46f6b76
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
15855
diff
changeset
|
232 |
} |
4e30a46f6b76
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
15855
diff
changeset
|
233 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
234 |
template <class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
235 |
E* ArrayAllocator<E>::reallocate(E* old_addr, size_t old_length, size_t new_length, MEMFLAGS flags) { |
37057 | 236 |
E* new_addr = (new_length > 0) |
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
237 |
? allocate(new_length, flags) |
37057 | 238 |
: NULL; |
23545
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
239 |
|
37057 | 240 |
if (new_addr != NULL && old_addr != NULL) { |
241 |
memcpy(new_addr, old_addr, MIN2(old_length, new_length) * sizeof(E)); |
|
242 |
} |
|
23545
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
243 |
|
37057 | 244 |
if (old_addr != NULL) { |
245 |
free(old_addr, old_length); |
|
246 |
} |
|
247 |
||
248 |
return new_addr; |
|
23545
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
249 |
} |
2c14fb03a06d
8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents:
19696
diff
changeset
|
250 |
|
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
251 |
template<class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
252 |
void ArrayAllocator<E>::free_malloc(E* addr, size_t length) { |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
253 |
MallocArrayAllocator<E>::free(addr, length); |
37057 | 254 |
} |
255 |
||
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
256 |
template<class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
257 |
void ArrayAllocator<E>::free_mmap(E* addr, size_t length) { |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
258 |
MmapArrayAllocator<E>::free(addr, length); |
37057 | 259 |
} |
260 |
||
46704
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
261 |
template<class E> |
211b3f6b75ef
8182169: ArrayAllocator should take MEMFLAGS as regular parameter
kbarrett
parents:
46625
diff
changeset
|
262 |
void ArrayAllocator<E>::free(E* addr, size_t length) { |
37057 | 263 |
if (addr != NULL) { |
264 |
if (should_use_malloc(length)) { |
|
265 |
free_malloc(addr, length); |
|
16682
4e30a46f6b76
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
15855
diff
changeset
|
266 |
} else { |
37057 | 267 |
free_mmap(addr, length); |
16682
4e30a46f6b76
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
15855
diff
changeset
|
268 |
} |
4e30a46f6b76
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
15855
diff
changeset
|
269 |
} |
4e30a46f6b76
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
15855
diff
changeset
|
270 |
} |
13195 | 271 |
|
7397 | 272 |
#endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |