author | rprotacio |
Mon, 23 Nov 2015 16:16:46 -0500 | |
changeset 34262 | 43560e879d6d |
parent 33611 | 9abd65805e19 |
child 35194 | 7151995ee79e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29697
92501504191b
8074459: Flags handling memory sizes should be of type size_t
jwilhelm
parents:
29199
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, 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 |
#include "precompiled.hpp" |
26 |
#include "memory/allocation.inline.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
27 |
#include "oops/constantPool.hpp" |
7397 | 28 |
#include "oops/oop.inline.hpp" |
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
24424
diff
changeset
|
29 |
#include "runtime/atomic.inline.hpp" |
7397 | 30 |
#include "runtime/handles.inline.hpp" |
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
14120
diff
changeset
|
31 |
#include "runtime/thread.inline.hpp" |
1 | 32 |
|
33 |
#ifdef ASSERT |
|
34 |
oop* HandleArea::allocate_handle(oop obj) { |
|
35 |
assert(_handle_mark_nesting > 1, "memory leak: allocating handle outside HandleMark"); |
|
36 |
assert(_no_handle_mark_nesting == 0, "allocating handle inside NoHandleMark"); |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
37 |
assert(obj->is_oop(), "not an oop: " INTPTR_FORMAT, p2i(obj)); |
1 | 38 |
return real_allocate_handle(obj); |
39 |
} |
|
40 |
||
41 |
Handle::Handle(Thread* thread, oop obj) { |
|
42 |
assert(thread == Thread::current(), "sanity check"); |
|
43 |
if (obj == NULL) { |
|
44 |
_handle = NULL; |
|
45 |
} else { |
|
46 |
_handle = thread->handle_area()->allocate_handle(obj); |
|
47 |
} |
|
48 |
} |
|
49 |
||
50 |
#endif |
|
51 |
||
52 |
static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) { |
|
53 |
oop* bottom = (oop*) chunk->bottom(); |
|
54 |
oop* top = (oop*) chunk_top; |
|
55 |
uintx handles_visited = top - bottom; |
|
56 |
assert(top >= bottom && top <= (oop*) chunk->top(), "just checking"); |
|
57 |
// during GC phase 3, a handle may be a forward pointer that |
|
58 |
// is not yet valid, so loosen the assertion |
|
59 |
while (bottom < top) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
60 |
// This test can be moved up but for now check every oop. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
61 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
62 |
assert((*bottom)->is_oop(), "handle should point to oop"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
63 |
|
1 | 64 |
f->do_oop(bottom++); |
65 |
} |
|
66 |
return handles_visited; |
|
67 |
} |
|
68 |
||
69 |
// Used for debugging handle allocation. |
|
70 |
NOT_PRODUCT(jint _nof_handlemarks = 0;) |
|
71 |
||
72 |
void HandleArea::oops_do(OopClosure* f) { |
|
73 |
uintx handles_visited = 0; |
|
74 |
// First handle the current chunk. It is filled to the high water mark. |
|
75 |
handles_visited += chunk_oops_do(f, _chunk, _hwm); |
|
76 |
// Then handle all previous chunks. They are completely filled. |
|
77 |
Chunk* k = _first; |
|
78 |
while(k != _chunk) { |
|
79 |
handles_visited += chunk_oops_do(f, k, k->top()); |
|
80 |
k = k->next(); |
|
81 |
} |
|
82 |
||
83 |
// The thread local handle areas should not get very large |
|
29697
92501504191b
8074459: Flags handling memory sizes should be of type size_t
jwilhelm
parents:
29199
diff
changeset
|
84 |
if (TraceHandleAllocation && (size_t)handles_visited > TotalHandleAllocationLimit) { |
1 | 85 |
#ifdef ASSERT |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
86 |
warning("%d: Visited in HandleMark : " SIZE_FORMAT, _nof_handlemarks, handles_visited); |
1 | 87 |
#else |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
88 |
warning("Visited in HandleMark : " SIZE_FORMAT, handles_visited); |
1 | 89 |
#endif |
90 |
} |
|
91 |
if (_prev != NULL) _prev->oops_do(f); |
|
92 |
} |
|
93 |
||
94 |
void HandleMark::initialize(Thread* thread) { |
|
95 |
_thread = thread; |
|
96 |
// Save area |
|
97 |
_area = thread->handle_area(); |
|
98 |
// Save current top |
|
99 |
_chunk = _area->_chunk; |
|
100 |
_hwm = _area->_hwm; |
|
101 |
_max = _area->_max; |
|
13195 | 102 |
_size_in_bytes = _area->_size_in_bytes; |
1 | 103 |
debug_only(_area->_handle_mark_nesting++); |
104 |
assert(_area->_handle_mark_nesting > 0, "must stack allocate HandleMarks"); |
|
105 |
debug_only(Atomic::inc(&_nof_handlemarks);) |
|
106 |
||
107 |
// Link this in the thread |
|
108 |
set_previous_handle_mark(thread->last_handle_mark()); |
|
109 |
thread->set_last_handle_mark(this); |
|
110 |
} |
|
111 |
||
112 |
||
113 |
HandleMark::~HandleMark() { |
|
114 |
HandleArea* area = _area; // help compilers with poor alias analysis |
|
115 |
assert(area == _thread->handle_area(), "sanity check"); |
|
116 |
assert(area->_handle_mark_nesting > 0, "must stack allocate HandleMarks" ); |
|
117 |
debug_only(area->_handle_mark_nesting--); |
|
118 |
||
119 |
// Debug code to trace the number of handles allocated per mark/ |
|
120 |
#ifdef ASSERT |
|
121 |
if (TraceHandleAllocation) { |
|
122 |
size_t handles = 0; |
|
123 |
Chunk *c = _chunk->next(); |
|
124 |
if (c == NULL) { |
|
125 |
handles = area->_hwm - _hwm; // no new chunk allocated |
|
126 |
} else { |
|
127 |
handles = _max - _hwm; // add rest in first chunk |
|
128 |
while(c != NULL) { |
|
129 |
handles += c->length(); |
|
130 |
c = c->next(); |
|
131 |
} |
|
132 |
handles -= area->_max - area->_hwm; // adjust for last trunk not full |
|
133 |
} |
|
134 |
handles /= sizeof(void *); // Adjust for size of a handle |
|
135 |
if (handles > HandleAllocationLimit) { |
|
136 |
// Note: _nof_handlemarks is only set in debug mode |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
137 |
warning("%d: Allocated in HandleMark : " SIZE_FORMAT, _nof_handlemarks, handles); |
1 | 138 |
} |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
139 |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
140 |
tty->print_cr("Handles " SIZE_FORMAT, handles); |
1 | 141 |
} |
142 |
#endif |
|
143 |
||
144 |
// Delete later chunks |
|
145 |
if( _chunk->next() ) { |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
146 |
// reset arena size before delete chunks. Otherwise, the total |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
147 |
// arena size could exceed total chunk size |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
148 |
assert(area->size_in_bytes() > size_in_bytes(), "Sanity check"); |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
149 |
area->set_size_in_bytes(size_in_bytes()); |
1 | 150 |
_chunk->next_chop(); |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
151 |
} else { |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
152 |
assert(area->size_in_bytes() == size_in_bytes(), "Sanity check"); |
1 | 153 |
} |
154 |
// Roll back arena to saved top markers |
|
155 |
area->_chunk = _chunk; |
|
156 |
area->_hwm = _hwm; |
|
157 |
area->_max = _max; |
|
158 |
#ifdef ASSERT |
|
159 |
// clear out first chunk (to detect allocation bugs) |
|
160 |
if (ZapVMHandleArea) { |
|
161 |
memset(_hwm, badHandleValue, _max - _hwm); |
|
162 |
} |
|
163 |
Atomic::dec(&_nof_handlemarks); |
|
164 |
#endif |
|
165 |
||
166 |
// Unlink this from the thread |
|
167 |
_thread->set_last_handle_mark(previous_handle_mark()); |
|
168 |
} |
|
169 |
||
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17376
diff
changeset
|
170 |
void* HandleMark::operator new(size_t size) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
171 |
return AllocateHeap(size, mtThread); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
172 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
173 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17376
diff
changeset
|
174 |
void* HandleMark::operator new [] (size_t size) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
175 |
return AllocateHeap(size, mtThread); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
176 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
177 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
178 |
void HandleMark::operator delete(void* p) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25468
diff
changeset
|
179 |
FreeHeap(p); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
180 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
181 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
182 |
void HandleMark::operator delete[](void* p) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25468
diff
changeset
|
183 |
FreeHeap(p); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
184 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
185 |
|
1 | 186 |
#ifdef ASSERT |
187 |
||
188 |
NoHandleMark::NoHandleMark() { |
|
189 |
HandleArea* area = Thread::current()->handle_area(); |
|
190 |
area->_no_handle_mark_nesting++; |
|
191 |
assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" ); |
|
192 |
} |
|
193 |
||
194 |
||
195 |
NoHandleMark::~NoHandleMark() { |
|
196 |
HandleArea* area = Thread::current()->handle_area(); |
|
197 |
assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" ); |
|
198 |
area->_no_handle_mark_nesting--; |
|
199 |
} |
|
200 |
||
201 |
||
202 |
ResetNoHandleMark::ResetNoHandleMark() { |
|
203 |
HandleArea* area = Thread::current()->handle_area(); |
|
204 |
_no_handle_mark_nesting = area->_no_handle_mark_nesting; |
|
205 |
area->_no_handle_mark_nesting = 0; |
|
206 |
} |
|
207 |
||
208 |
||
209 |
ResetNoHandleMark::~ResetNoHandleMark() { |
|
210 |
HandleArea* area = Thread::current()->handle_area(); |
|
211 |
area->_no_handle_mark_nesting = _no_handle_mark_nesting; |
|
212 |
} |
|
213 |
||
29199
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
27880
diff
changeset
|
214 |
bool instanceKlassHandle::is_instanceKlass(const Klass* k) { |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33148
diff
changeset
|
215 |
// Need this to avoid circular include dependency |
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33148
diff
changeset
|
216 |
return k->is_instance_klass(); |
29199
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
27880
diff
changeset
|
217 |
} |
db7ae483ecb2
8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents:
27880
diff
changeset
|
218 |
|
1 | 219 |
#endif |