Mercurial > hg > truffle
annotate src/share/vm/memory/allocation.inline.hpp @ 13409:77b028ba548c
8028396: Minimal VM: undefined symbol: _ZN23JvmtiCurrentBreakpoints11metadata_doEPFvP8MetadataE
Summary: Minimal VM doesn't run
Reviewed-by: coleenp, dholmes
author | jprovino |
---|---|
date | Tue, 19 Nov 2013 16:26:54 -0500 |
parents | 9758d9f36299 |
children | 833b0f92429a |
rev | line source |
---|---|
0 | 1 /* |
8675
63e54c37ac64
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
6872
diff
changeset
|
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |
26 #define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP | |
27 | |
8675
63e54c37ac64
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
6872
diff
changeset
|
28 #include "runtime/atomic.inline.hpp" |
1972 | 29 #include "runtime/os.hpp" |
30 | |
0 | 31 // Explicit C-heap memory management |
32 | |
33 void trace_heap_malloc(size_t size, const char* name, void *p); | |
34 void trace_heap_free(void *p); | |
35 | |
2255 | 36 #ifndef PRODUCT |
2250 | 37 // Increments unsigned long value for statistics (not atomic on MP). |
38 inline void inc_stat_counter(volatile julong* dest, julong add_value) { | |
2255 | 39 #if defined(SPARC) || defined(X86) |
40 // Sparc and X86 have atomic jlong (8 bytes) instructions | |
2250 | 41 julong value = Atomic::load((volatile jlong*)dest); |
42 value += add_value; | |
43 Atomic::store((jlong)value, (volatile jlong*)dest); | |
2255 | 44 #else |
45 // possible word-tearing during load/store | |
46 *dest += add_value; | |
47 #endif | |
2250 | 48 } |
2255 | 49 #endif |
0 | 50 |
51 // allocate using malloc; will fail if no memory available | |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
52 inline char* AllocateHeap(size_t size, MEMFLAGS flags, address pc = 0, |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
53 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
6197 | 54 if (pc == 0) { |
55 pc = CURRENT_PC; | |
56 } | |
57 char* p = (char*) os::malloc(size, flags, pc); | |
0 | 58 #ifdef ASSERT |
6197 | 59 if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p); |
0 | 60 #endif |
10161
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
10135
diff
changeset
|
61 if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
10135
diff
changeset
|
62 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap"); |
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
10135
diff
changeset
|
63 } |
6197 | 64 return p; |
65 } | |
66 | |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
67 inline char* ReallocateHeap(char *old, size_t size, MEMFLAGS flags, |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
68 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
6197 | 69 char* p = (char*) os::realloc(old, size, flags, CURRENT_PC); |
70 #ifdef ASSERT | |
71 if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p); | |
72 #endif | |
10161
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
10135
diff
changeset
|
73 if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { |
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
10135
diff
changeset
|
74 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap"); |
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
10135
diff
changeset
|
75 } |
0 | 76 return p; |
77 } | |
78 | |
6197 | 79 inline void FreeHeap(void* p, MEMFLAGS memflags = mtInternal) { |
0 | 80 #ifdef ASSERT |
81 if (PrintMallocFree) trace_heap_free(p); | |
82 #endif | |
6197 | 83 os::free(p, memflags); |
0 | 84 } |
1972 | 85 |
6197 | 86 |
87 template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size, | |
12146
9758d9f36299
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
10969
diff
changeset
|
88 address caller_pc) throw() { |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
89 void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC)); |
10135 | 90 #ifdef ASSERT |
6197 | 91 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
92 #endif |
10135 | 93 return p; |
6197 | 94 } |
95 | |
96 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size, | |
12146
9758d9f36299
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
10969
diff
changeset
|
97 const std::nothrow_t& nothrow_constant, address caller_pc) throw() { |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
98 void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC), |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6842
diff
changeset
|
99 AllocFailStrategy::RETURN_NULL); |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
100 #ifdef ASSERT |
6197 | 101 if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p); |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
102 #endif |
6197 | 103 return p; |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
104 } |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
105 |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
106 template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size, |
12146
9758d9f36299
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
10969
diff
changeset
|
107 address caller_pc) throw() { |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
108 return CHeapObj<F>::operator new(size, caller_pc); |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
109 } |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
110 |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
111 template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size, |
12146
9758d9f36299
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
10969
diff
changeset
|
112 const std::nothrow_t& nothrow_constant, address caller_pc) throw() { |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
113 return CHeapObj<F>::operator new(size, nothrow_constant, caller_pc); |
6197 | 114 } |
115 | |
116 template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){ | |
10271
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
117 FreeHeap(p, F); |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
118 } |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
119 |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
120 template <MEMFLAGS F> void CHeapObj<F>::operator delete [](void* p){ |
f9be75d21404
8012902: remove use of global operator new - take 2
minqi
parents:
10221
diff
changeset
|
121 FreeHeap(p, F); |
6197 | 122 } |
123 | |
9073
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
124 template <class E, MEMFLAGS F> |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
125 E* ArrayAllocator<E, F>::allocate(size_t length) { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
126 assert(_addr == NULL, "Already in use"); |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
127 |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
128 _size = sizeof(E) * length; |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
129 _use_malloc = _size < ArrayAllocatorMallocLimit; |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
130 |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
131 if (_use_malloc) { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
132 _addr = AllocateHeap(_size, F); |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
133 if (_addr == NULL && _size >= (size_t)os::vm_allocation_granularity()) { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
134 // malloc failed let's try with mmap instead |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
135 _use_malloc = false; |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
136 } else { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
137 return (E*)_addr; |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
138 } |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
139 } |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
140 |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
141 int alignment = os::vm_allocation_granularity(); |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
142 _size = align_size_up(_size, alignment); |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
143 |
10221
c18152e0554e
8013120: NMT: Kitchensink crashes with assert(next_region == NULL || !next_region->is_committed_region()) failed: Sanity check
zgu
parents:
10161
diff
changeset
|
144 _addr = os::reserve_memory(_size, NULL, alignment, F); |
9073
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
145 if (_addr == NULL) { |
10161
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
10135
diff
changeset
|
146 vm_exit_out_of_memory(_size, OOM_MMAP_ERROR, "Allocator (reserve)"); |
9073
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
147 } |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
148 |
10969
a837fa3d3f86
8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents:
10271
diff
changeset
|
149 os::commit_memory_or_exit(_addr, _size, !ExecMem, "Allocator (commit)"); |
9073
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
150 |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
151 return (E*)_addr; |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
152 } |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
153 |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
154 template<class E, MEMFLAGS F> |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
155 void ArrayAllocator<E, F>::free() { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
156 if (_addr != NULL) { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
157 if (_use_malloc) { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
158 FreeHeap(_addr, F); |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
159 } else { |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
160 os::release_memory(_addr, _size); |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
161 } |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
162 _addr = NULL; |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
163 } |
83f27710f5f7
7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents:
8675
diff
changeset
|
164 } |
6197 | 165 |
1972 | 166 #endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP |