author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46968 | hotspot/src/share/vm/runtime/handles.cpp@9119841280f4 |
child 47778 | 46cb6af585d4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
40655
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, 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" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
36583
diff
changeset
|
29 |
#include "runtime/atomic.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"); |
|
46968
9119841280f4
8160399: is_oop_or_null involves undefined behavior
coleenp
parents:
46329
diff
changeset
|
37 |
assert(oopDesc::is_oop(obj), "not an oop: " INTPTR_FORMAT, p2i(obj)); |
1 | 38 |
return real_allocate_handle(obj); |
39 |
} |
|
35194
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
40 |
#endif |
1 | 41 |
|
35194
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
42 |
// Copy constructors and destructors for metadata handles |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
43 |
// These do too much to inline. |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
44 |
#define DEF_METADATA_HANDLE_FN_NOINLINE(name, type) \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
45 |
name##Handle::name##Handle(const name##Handle &h) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
46 |
_value = h._value; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
47 |
if (_value != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
48 |
assert(_value->is_valid(), "obj is valid"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
49 |
if (h._thread != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
50 |
assert(h._thread == Thread::current(), "thread must be current");\ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
51 |
_thread = h._thread; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
52 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
53 |
_thread = Thread::current(); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
54 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
55 |
assert (_thread->is_in_stack((address)this), "not on stack?"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
56 |
_thread->metadata_handles()->push((Metadata*)_value); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
57 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
58 |
_thread = NULL; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
59 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
60 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
61 |
name##Handle& name##Handle::operator=(const name##Handle &s) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
62 |
remove(); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
63 |
_value = s._value; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
64 |
if (_value != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
65 |
assert(_value->is_valid(), "obj is valid"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
66 |
if (s._thread != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
67 |
assert(s._thread == Thread::current(), "thread must be current");\ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
68 |
_thread = s._thread; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
69 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
70 |
_thread = Thread::current(); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
71 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
72 |
assert (_thread->is_in_stack((address)this), "not on stack?"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
73 |
_thread->metadata_handles()->push((Metadata*)_value); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
74 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
75 |
_thread = NULL; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
76 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
77 |
return *this; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
78 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
79 |
inline void name##Handle::remove() { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
80 |
if (_value != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
81 |
int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
82 |
assert(i!=-1, "not in metadata_handles list"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
83 |
_thread->metadata_handles()->remove_at(i); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
84 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
85 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
86 |
name##Handle::~name##Handle () { remove(); } \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
87 |
|
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
88 |
DEF_METADATA_HANDLE_FN_NOINLINE(method, Method) |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
89 |
DEF_METADATA_HANDLE_FN_NOINLINE(constantPool, ConstantPool) |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
90 |
|
1 | 91 |
|
92 |
static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) { |
|
93 |
oop* bottom = (oop*) chunk->bottom(); |
|
94 |
oop* top = (oop*) chunk_top; |
|
95 |
uintx handles_visited = top - bottom; |
|
96 |
assert(top >= bottom && top <= (oop*) chunk->top(), "just checking"); |
|
97 |
// during GC phase 3, a handle may be a forward pointer that |
|
98 |
// is not yet valid, so loosen the assertion |
|
99 |
while (bottom < top) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
100 |
// 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
|
101 |
|
46968
9119841280f4
8160399: is_oop_or_null involves undefined behavior
coleenp
parents:
46329
diff
changeset
|
102 |
assert(oopDesc::is_oop(*bottom), "handle should point to oop"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
103 |
|
1 | 104 |
f->do_oop(bottom++); |
105 |
} |
|
106 |
return handles_visited; |
|
107 |
} |
|
108 |
||
109 |
// Used for debugging handle allocation. |
|
110 |
NOT_PRODUCT(jint _nof_handlemarks = 0;) |
|
111 |
||
112 |
void HandleArea::oops_do(OopClosure* f) { |
|
113 |
uintx handles_visited = 0; |
|
114 |
// First handle the current chunk. It is filled to the high water mark. |
|
115 |
handles_visited += chunk_oops_do(f, _chunk, _hwm); |
|
116 |
// Then handle all previous chunks. They are completely filled. |
|
117 |
Chunk* k = _first; |
|
118 |
while(k != _chunk) { |
|
119 |
handles_visited += chunk_oops_do(f, k, k->top()); |
|
120 |
k = k->next(); |
|
121 |
} |
|
122 |
||
123 |
if (_prev != NULL) _prev->oops_do(f); |
|
124 |
} |
|
125 |
||
126 |
void HandleMark::initialize(Thread* thread) { |
|
127 |
_thread = thread; |
|
128 |
// Save area |
|
129 |
_area = thread->handle_area(); |
|
130 |
// Save current top |
|
131 |
_chunk = _area->_chunk; |
|
132 |
_hwm = _area->_hwm; |
|
133 |
_max = _area->_max; |
|
13195 | 134 |
_size_in_bytes = _area->_size_in_bytes; |
1 | 135 |
debug_only(_area->_handle_mark_nesting++); |
136 |
assert(_area->_handle_mark_nesting > 0, "must stack allocate HandleMarks"); |
|
137 |
debug_only(Atomic::inc(&_nof_handlemarks);) |
|
138 |
||
139 |
// Link this in the thread |
|
140 |
set_previous_handle_mark(thread->last_handle_mark()); |
|
141 |
thread->set_last_handle_mark(this); |
|
142 |
} |
|
143 |
||
144 |
||
145 |
HandleMark::~HandleMark() { |
|
146 |
HandleArea* area = _area; // help compilers with poor alias analysis |
|
147 |
assert(area == _thread->handle_area(), "sanity check"); |
|
148 |
assert(area->_handle_mark_nesting > 0, "must stack allocate HandleMarks" ); |
|
149 |
debug_only(area->_handle_mark_nesting--); |
|
150 |
||
151 |
// Delete later chunks |
|
152 |
if( _chunk->next() ) { |
|
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
153 |
// 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
|
154 |
// arena size could exceed total chunk size |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
155 |
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
|
156 |
area->set_size_in_bytes(size_in_bytes()); |
1 | 157 |
_chunk->next_chop(); |
14120
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
158 |
} else { |
7d298141c258
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
14078
diff
changeset
|
159 |
assert(area->size_in_bytes() == size_in_bytes(), "Sanity check"); |
1 | 160 |
} |
161 |
// Roll back arena to saved top markers |
|
162 |
area->_chunk = _chunk; |
|
163 |
area->_hwm = _hwm; |
|
164 |
area->_max = _max; |
|
165 |
#ifdef ASSERT |
|
166 |
// clear out first chunk (to detect allocation bugs) |
|
167 |
if (ZapVMHandleArea) { |
|
168 |
memset(_hwm, badHandleValue, _max - _hwm); |
|
169 |
} |
|
170 |
Atomic::dec(&_nof_handlemarks); |
|
171 |
#endif |
|
172 |
||
173 |
// Unlink this from the thread |
|
174 |
_thread->set_last_handle_mark(previous_handle_mark()); |
|
175 |
} |
|
176 |
||
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17376
diff
changeset
|
177 |
void* HandleMark::operator new(size_t size) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
178 |
return AllocateHeap(size, mtThread); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
179 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
180 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17376
diff
changeset
|
181 |
void* HandleMark::operator new [] (size_t size) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
182 |
return AllocateHeap(size, mtThread); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
183 |
} |
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 |
void HandleMark::operator delete(void* p) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25468
diff
changeset
|
186 |
FreeHeap(p); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
187 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
188 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
189 |
void HandleMark::operator delete[](void* p) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25468
diff
changeset
|
190 |
FreeHeap(p); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
191 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
192 |
|
1 | 193 |
#ifdef ASSERT |
194 |
||
195 |
NoHandleMark::NoHandleMark() { |
|
196 |
HandleArea* area = Thread::current()->handle_area(); |
|
197 |
area->_no_handle_mark_nesting++; |
|
198 |
assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" ); |
|
199 |
} |
|
200 |
||
201 |
||
202 |
NoHandleMark::~NoHandleMark() { |
|
203 |
HandleArea* area = Thread::current()->handle_area(); |
|
204 |
assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" ); |
|
205 |
area->_no_handle_mark_nesting--; |
|
206 |
} |
|
207 |
||
208 |
||
209 |
ResetNoHandleMark::ResetNoHandleMark() { |
|
210 |
HandleArea* area = Thread::current()->handle_area(); |
|
211 |
_no_handle_mark_nesting = area->_no_handle_mark_nesting; |
|
212 |
area->_no_handle_mark_nesting = 0; |
|
213 |
} |
|
214 |
||
215 |
||
216 |
ResetNoHandleMark::~ResetNoHandleMark() { |
|
217 |
HandleArea* area = Thread::current()->handle_area(); |
|
218 |
area->_no_handle_mark_nesting = _no_handle_mark_nesting; |
|
219 |
} |
|
220 |
||
221 |
#endif |