author | mockner |
Fri, 29 Apr 2016 22:40:51 -0400 | |
changeset 38151 | fffedc5e5cf8 |
parent 38133 | 78b95467b9f1 |
child 46495 | 34f7d403039f |
permissions | -rw-r--r-- |
1 | 1 |
/* |
38133
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
33148
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 |
#include "precompiled.hpp" |
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
13728
diff
changeset
|
26 |
#include "code/codeCache.hpp" |
7397 | 27 |
#include "code/compiledIC.hpp" |
28 |
#include "code/icBuffer.hpp" |
|
29 |
#include "code/nmethod.hpp" |
|
30 |
#include "code/scopeDesc.hpp" |
|
30764 | 31 |
#include "gc/shared/collectedHeap.inline.hpp" |
7397 | 32 |
#include "interpreter/interpreter.hpp" |
33 |
#include "interpreter/linkResolver.hpp" |
|
34 |
#include "memory/resourceArea.hpp" |
|
35 |
#include "memory/universe.inline.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
36 |
#include "oops/method.hpp" |
7397 | 37 |
#include "oops/oop.inline.hpp" |
38 |
#include "runtime/mutexLocker.hpp" |
|
39 |
#include "runtime/stubRoutines.hpp" |
|
1 | 40 |
|
41 |
DEF_STUB_INTERFACE(ICStub); |
|
42 |
||
43 |
StubQueue* InlineCacheBuffer::_buffer = NULL; |
|
44 |
ICStub* InlineCacheBuffer::_next_stub = NULL; |
|
45 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
46 |
CompiledICHolder* InlineCacheBuffer::_pending_released = NULL; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
47 |
int InlineCacheBuffer::_pending_count = 0; |
1 | 48 |
|
49 |
void ICStub::finalize() { |
|
50 |
if (!is_empty()) { |
|
51 |
ResourceMark rm; |
|
38133
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
33148
diff
changeset
|
52 |
CompiledIC *ic = CompiledIC_at(CodeCache::find_compiled(ic_site()), ic_site()); |
78b95467b9f1
8151956: Support non-continuous CodeBlobs in HotSpot
rbackman
parents:
33148
diff
changeset
|
53 |
assert(CodeCache::find_compiled(ic->instruction_address()) != NULL, "inline cache in non-compiled?"); |
1 | 54 |
|
55 |
assert(this == ICStub_from_destination_address(ic->stub_address()), "wrong owner of ic buffer"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
56 |
ic->set_ic_destination_and_value(destination(), cached_value()); |
1 | 57 |
} |
58 |
} |
|
59 |
||
60 |
||
61 |
address ICStub::destination() const { |
|
62 |
return InlineCacheBuffer::ic_buffer_entry_point(code_begin()); |
|
63 |
} |
|
64 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
65 |
void* ICStub::cached_value() const { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
66 |
return InlineCacheBuffer::ic_buffer_cached_value(code_begin()); |
1 | 67 |
} |
68 |
||
69 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
70 |
void ICStub::set_stub(CompiledIC *ic, void* cached_val, address dest_addr) { |
1 | 71 |
// We cannot store a pointer to the 'ic' object, since it is resource allocated. Instead we |
72 |
// store the location of the inline cache. Then we have enough information recreate the CompiledIC |
|
73 |
// object when we need to remove the stub. |
|
74 |
_ic_site = ic->instruction_address(); |
|
75 |
||
76 |
// Assemble new stub |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
77 |
InlineCacheBuffer::assemble_ic_buffer_code(code_begin(), cached_val, dest_addr); |
1 | 78 |
assert(destination() == dest_addr, "can recover destination"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
79 |
assert(cached_value() == cached_val, "can recover destination"); |
1 | 80 |
} |
81 |
||
82 |
||
83 |
void ICStub::clear() { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
84 |
if (CompiledIC::is_icholder_entry(destination())) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
85 |
InlineCacheBuffer::queue_for_release((CompiledICHolder*)cached_value()); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
86 |
} |
1 | 87 |
_ic_site = NULL; |
88 |
} |
|
89 |
||
90 |
||
91 |
#ifndef PRODUCT |
|
92 |
// anybody calling to this stub will trap |
|
93 |
||
94 |
void ICStub::verify() { |
|
95 |
} |
|
96 |
||
97 |
void ICStub::print() { |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
30764
diff
changeset
|
98 |
tty->print_cr("ICStub: site: " INTPTR_FORMAT, p2i(_ic_site)); |
1 | 99 |
} |
100 |
#endif |
|
101 |
||
102 |
//----------------------------------------------------------------------------------------------- |
|
103 |
// Implementation of InlineCacheBuffer |
|
104 |
||
105 |
void InlineCacheBuffer::init_next_stub() { |
|
106 |
ICStub* ic_stub = (ICStub*)buffer()->request_committed (ic_stub_code_size()); |
|
107 |
assert (ic_stub != NULL, "no room for a single stub"); |
|
108 |
set_next_stub(ic_stub); |
|
109 |
} |
|
110 |
||
111 |
void InlineCacheBuffer::initialize() { |
|
112 |
if (_buffer != NULL) return; // already initialized |
|
113 |
_buffer = new StubQueue(new ICStubInterface, 10*K, InlineCacheBuffer_lock, "InlineCacheBuffer"); |
|
114 |
assert (_buffer != NULL, "cannot allocate InlineCacheBuffer"); |
|
115 |
init_next_stub(); |
|
116 |
} |
|
117 |
||
118 |
||
119 |
ICStub* InlineCacheBuffer::new_ic_stub() { |
|
120 |
while (true) { |
|
121 |
ICStub* ic_stub = (ICStub*)buffer()->request_committed(ic_stub_code_size()); |
|
122 |
if (ic_stub != NULL) { |
|
123 |
return ic_stub; |
|
124 |
} |
|
125 |
// we ran out of inline cache buffer space; must enter safepoint. |
|
126 |
// We do this by forcing a safepoint |
|
127 |
EXCEPTION_MARK; |
|
128 |
||
129 |
VM_ForceSafepoint vfs; |
|
130 |
VMThread::execute(&vfs); |
|
131 |
// We could potential get an async. exception at this point. |
|
132 |
// In that case we will rethrow it to ourselvs. |
|
133 |
if (HAS_PENDING_EXCEPTION) { |
|
134 |
oop exception = PENDING_EXCEPTION; |
|
135 |
CLEAR_PENDING_EXCEPTION; |
|
136 |
Thread::send_async_exception(JavaThread::current()->threadObj(), exception); |
|
137 |
} |
|
138 |
} |
|
139 |
ShouldNotReachHere(); |
|
140 |
return NULL; |
|
141 |
} |
|
142 |
||
143 |
||
144 |
void InlineCacheBuffer::update_inline_caches() { |
|
145 |
if (buffer()->number_of_stubs() > 1) { |
|
146 |
if (TraceICBuffer) { |
|
147 |
tty->print_cr("[updating inline caches with %d stubs]", buffer()->number_of_stubs()); |
|
148 |
} |
|
149 |
buffer()->remove_all(); |
|
150 |
init_next_stub(); |
|
151 |
} |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
152 |
release_pending_icholders(); |
1 | 153 |
} |
154 |
||
155 |
||
156 |
bool InlineCacheBuffer::contains(address instruction_address) { |
|
157 |
return buffer()->contains(instruction_address); |
|
158 |
} |
|
159 |
||
160 |
||
161 |
bool InlineCacheBuffer::is_empty() { |
|
162 |
return buffer()->number_of_stubs() == 1; // always has sentinel |
|
163 |
} |
|
164 |
||
165 |
||
166 |
void InlineCacheBuffer_init() { |
|
167 |
InlineCacheBuffer::initialize(); |
|
168 |
} |
|
169 |
||
170 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
171 |
void InlineCacheBuffer::create_transition_stub(CompiledIC *ic, void* cached_value, address entry) { |
1 | 172 |
assert(!SafepointSynchronize::is_at_safepoint(), "should not be called during a safepoint"); |
173 |
assert (CompiledIC_lock->is_locked(), ""); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
174 |
if (TraceICBuffer) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
175 |
tty->print_cr(" create transition stub for " INTPTR_FORMAT " destination " INTPTR_FORMAT " cached value " INTPTR_FORMAT, |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
30764
diff
changeset
|
176 |
p2i(ic->instruction_address()), p2i(entry), p2i(cached_value)); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
177 |
} |
1 | 178 |
|
179 |
// If an transition stub is already associate with the inline cache, then we remove the association. |
|
180 |
if (ic->is_in_transition_state()) { |
|
181 |
ICStub* old_stub = ICStub_from_destination_address(ic->stub_address()); |
|
182 |
old_stub->clear(); |
|
183 |
} |
|
184 |
||
185 |
// allocate and initialize new "out-of-line" inline-cache |
|
186 |
ICStub* ic_stub = get_next_stub(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
187 |
ic_stub->set_stub(ic, cached_value, entry); |
1 | 188 |
|
189 |
// Update inline cache in nmethod to point to new "out-of-line" allocated inline cache |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
190 |
ic->set_ic_destination(ic_stub); |
1 | 191 |
|
192 |
set_next_stub(new_ic_stub()); // can cause safepoint synchronization |
|
193 |
} |
|
194 |
||
195 |
||
196 |
address InlineCacheBuffer::ic_destination_for(CompiledIC *ic) { |
|
197 |
ICStub* stub = ICStub_from_destination_address(ic->stub_address()); |
|
198 |
return stub->destination(); |
|
199 |
} |
|
200 |
||
201 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
202 |
void* InlineCacheBuffer::cached_value_for(CompiledIC *ic) { |
1 | 203 |
ICStub* stub = ICStub_from_destination_address(ic->stub_address()); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
204 |
return stub->cached_value(); |
1 | 205 |
} |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
206 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
207 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
208 |
// Free CompiledICHolder*s that are no longer in use |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
209 |
void InlineCacheBuffer::release_pending_icholders() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
210 |
assert(SafepointSynchronize::is_at_safepoint(), "should only be called during a safepoint"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
211 |
CompiledICHolder* holder = _pending_released; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
212 |
_pending_released = NULL; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
213 |
while (holder != NULL) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
214 |
CompiledICHolder* next = holder->next(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
215 |
delete holder; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
216 |
holder = next; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
217 |
_pending_count--; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
218 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
219 |
assert(_pending_count == 0, "wrong count"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
220 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
221 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
222 |
// Enqueue this icholder for release during the next safepoint. It's |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
223 |
// not safe to free them until them since they might be visible to |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
224 |
// another thread. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
225 |
void InlineCacheBuffer::queue_for_release(CompiledICHolder* icholder) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
226 |
MutexLockerEx mex(InlineCacheBuffer_lock); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
227 |
icholder->set_next(_pending_released); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
228 |
_pending_released = icholder; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
229 |
_pending_count++; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
230 |
if (TraceICBuffer) { |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
30764
diff
changeset
|
231 |
tty->print_cr("enqueueing icholder " INTPTR_FORMAT " to be freed", p2i(icholder)); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
232 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
233 |
} |