author | redestad |
Mon, 01 Jul 2019 12:16:58 +0200 | |
changeset 55537 | 4309fedaf7dc |
parent 53682 | e30211561a17 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53682 | 2 |
* Copyright (c) 1997, 2019, 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" |
29 |
#include "runtime/handles.inline.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
14120
diff
changeset
|
30 |
#include "runtime/thread.inline.hpp" |
1 | 31 |
|
32 |
#ifdef ASSERT |
|
33 |
oop* HandleArea::allocate_handle(oop obj) { |
|
34 |
assert(_handle_mark_nesting > 1, "memory leak: allocating handle outside HandleMark"); |
|
35 |
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
|
36 |
assert(oopDesc::is_oop(obj), "not an oop: " INTPTR_FORMAT, p2i(obj)); |
1 | 37 |
return real_allocate_handle(obj); |
38 |
} |
|
35194
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
39 |
#endif |
1 | 40 |
|
35194
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
41 |
// Copy constructors and destructors for metadata handles |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
42 |
// These do too much to inline. |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
43 |
#define DEF_METADATA_HANDLE_FN_NOINLINE(name, type) \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
44 |
name##Handle::name##Handle(const name##Handle &h) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
45 |
_value = h._value; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
46 |
if (_value != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
47 |
assert(_value->is_valid(), "obj is valid"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
48 |
if (h._thread != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
49 |
assert(h._thread == Thread::current(), "thread must be current");\ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
50 |
_thread = h._thread; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
51 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
52 |
_thread = Thread::current(); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
53 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
54 |
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
|
55 |
_thread->metadata_handles()->push((Metadata*)_value); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
56 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
57 |
_thread = NULL; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
58 |
} \ |
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 |
name##Handle& name##Handle::operator=(const name##Handle &s) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
61 |
remove(); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
62 |
_value = s._value; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
63 |
if (_value != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
64 |
assert(_value->is_valid(), "obj is valid"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
65 |
if (s._thread != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
66 |
assert(s._thread == Thread::current(), "thread must be current");\ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
67 |
_thread = s._thread; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
68 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
69 |
_thread = Thread::current(); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
70 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
71 |
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
|
72 |
_thread->metadata_handles()->push((Metadata*)_value); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
73 |
} else { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
74 |
_thread = NULL; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
75 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
76 |
return *this; \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
77 |
} \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
78 |
inline void name##Handle::remove() { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
79 |
if (_value != NULL) { \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
80 |
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
|
81 |
assert(i!=-1, "not in metadata_handles list"); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
82 |
_thread->metadata_handles()->remove_at(i); \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
83 |
} \ |
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 |
name##Handle::~name##Handle () { remove(); } \ |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
86 |
|
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
87 |
DEF_METADATA_HANDLE_FN_NOINLINE(method, Method) |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
88 |
DEF_METADATA_HANDLE_FN_NOINLINE(constantPool, ConstantPool) |
7151995ee79e
8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents:
33611
diff
changeset
|
89 |
|
1 | 90 |
|
91 |
static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) { |
|
92 |
oop* bottom = (oop*) chunk->bottom(); |
|
93 |
oop* top = (oop*) chunk_top; |
|
94 |
uintx handles_visited = top - bottom; |
|
95 |
assert(top >= bottom && top <= (oop*) chunk->top(), "just checking"); |
|
96 |
// during GC phase 3, a handle may be a forward pointer that |
|
97 |
// is not yet valid, so loosen the assertion |
|
98 |
while (bottom < top) { |
|
99 |
f->do_oop(bottom++); |
|
100 |
} |
|
101 |
return handles_visited; |
|
102 |
} |
|
103 |
||
104 |
void HandleArea::oops_do(OopClosure* f) { |
|
105 |
uintx handles_visited = 0; |
|
106 |
// First handle the current chunk. It is filled to the high water mark. |
|
107 |
handles_visited += chunk_oops_do(f, _chunk, _hwm); |
|
108 |
// Then handle all previous chunks. They are completely filled. |
|
109 |
Chunk* k = _first; |
|
110 |
while(k != _chunk) { |
|
111 |
handles_visited += chunk_oops_do(f, k, k->top()); |
|
112 |
k = k->next(); |
|
113 |
} |
|
114 |
||
115 |
if (_prev != NULL) _prev->oops_do(f); |
|
116 |
} |
|
117 |
||
118 |
void HandleMark::initialize(Thread* thread) { |
|
119 |
_thread = thread; |
|
120 |
// Save area |
|
121 |
_area = thread->handle_area(); |
|
122 |
// Save current top |
|
123 |
_chunk = _area->_chunk; |
|
124 |
_hwm = _area->_hwm; |
|
125 |
_max = _area->_max; |
|
13195 | 126 |
_size_in_bytes = _area->_size_in_bytes; |
1 | 127 |
debug_only(_area->_handle_mark_nesting++); |
128 |
assert(_area->_handle_mark_nesting > 0, "must stack allocate HandleMarks"); |
|
129 |
||
130 |
// Link this in the thread |
|
131 |
set_previous_handle_mark(thread->last_handle_mark()); |
|
132 |
thread->set_last_handle_mark(this); |
|
133 |
} |
|
134 |
||
135 |
HandleMark::~HandleMark() { |
|
53682 | 136 |
assert(_area == _thread->handle_area(), "sanity check"); |
137 |
assert(_area->_handle_mark_nesting > 0, "must stack allocate HandleMarks" ); |
|
1 | 138 |
|
53682 | 139 |
pop_and_restore(); |
1 | 140 |
#ifdef ASSERT |
141 |
// clear out first chunk (to detect allocation bugs) |
|
142 |
if (ZapVMHandleArea) { |
|
143 |
memset(_hwm, badHandleValue, _max - _hwm); |
|
144 |
} |
|
145 |
#endif |
|
146 |
||
147 |
// Unlink this from the thread |
|
148 |
_thread->set_last_handle_mark(previous_handle_mark()); |
|
149 |
} |
|
150 |
||
53682 | 151 |
void HandleMark::chop_later_chunks() { |
152 |
// reset arena size before delete chunks. Otherwise, the total |
|
153 |
// arena size could exceed total chunk size |
|
154 |
_area->set_size_in_bytes(size_in_bytes()); |
|
155 |
_chunk->next_chop(); |
|
156 |
} |
|
157 |
||
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17376
diff
changeset
|
158 |
void* HandleMark::operator new(size_t size) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
159 |
return AllocateHeap(size, mtThread); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
160 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
161 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17376
diff
changeset
|
162 |
void* HandleMark::operator new [] (size_t size) throw() { |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
163 |
return AllocateHeap(size, mtThread); |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
164 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
165 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
166 |
void HandleMark::operator delete(void* p) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25468
diff
changeset
|
167 |
FreeHeap(p); |
17376
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
168 |
} |
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
169 |
|
4ee999c3c007
8012902: remove use of global operator new - take 2
minqi
parents:
14583
diff
changeset
|
170 |
void HandleMark::operator delete[](void* p) { |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
25468
diff
changeset
|
171 |
FreeHeap(p); |
17376
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 |
|
1 | 174 |
#ifdef ASSERT |
175 |
||
176 |
NoHandleMark::NoHandleMark() { |
|
177 |
HandleArea* area = Thread::current()->handle_area(); |
|
178 |
area->_no_handle_mark_nesting++; |
|
179 |
assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" ); |
|
180 |
} |
|
181 |
||
182 |
||
183 |
NoHandleMark::~NoHandleMark() { |
|
184 |
HandleArea* area = Thread::current()->handle_area(); |
|
185 |
assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" ); |
|
186 |
area->_no_handle_mark_nesting--; |
|
187 |
} |
|
188 |
||
189 |
||
190 |
ResetNoHandleMark::ResetNoHandleMark() { |
|
191 |
HandleArea* area = Thread::current()->handle_area(); |
|
192 |
_no_handle_mark_nesting = area->_no_handle_mark_nesting; |
|
193 |
area->_no_handle_mark_nesting = 0; |
|
194 |
} |
|
195 |
||
196 |
||
197 |
ResetNoHandleMark::~ResetNoHandleMark() { |
|
198 |
HandleArea* area = Thread::current()->handle_area(); |
|
199 |
area->_no_handle_mark_nesting = _no_handle_mark_nesting; |
|
200 |
} |
|
201 |
||
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49013
diff
changeset
|
202 |
#endif // ASSERT |