author | coleenp |
Wed, 02 May 2018 11:28:49 -0400 | |
changeset 50416 | ef980b9ac191 |
parent 49969 | 8624981f1ffa |
child 50995 | 3c59afe1afc9 |
permissions | -rw-r--r-- |
38133 | 1 |
/* |
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48557
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
38133 | 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 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "code/compiledIC.hpp" |
|
46623
261b9d05b79d
8183299: Improve inlining of CompiledMethod methods into frame::sender
redestad
parents:
42650
diff
changeset
|
27 |
#include "code/compiledMethod.inline.hpp" |
38133 | 28 |
#include "code/scopeDesc.hpp" |
29 |
#include "code/codeCache.hpp" |
|
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
48955
diff
changeset
|
30 |
#include "interpreter/bytecode.inline.hpp" |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
31 |
#include "logging/log.hpp" |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
32 |
#include "logging/logTag.hpp" |
38133 | 33 |
#include "memory/resourceArea.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
34 |
#include "oops/methodData.hpp" |
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
48955
diff
changeset
|
35 |
#include "oops/method.inline.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49449
diff
changeset
|
36 |
#include "prims/methodHandles.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
49340
diff
changeset
|
37 |
#include "runtime/handles.inline.hpp" |
38133 | 38 |
#include "runtime/mutexLocker.hpp" |
39 |
||
42040
70ec5a09a0d5
8166377: is_compiled_by_jvmci hot in some profiles - improve nmethod compiler type detection
neliasso
parents:
39430
diff
changeset
|
40 |
CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments) |
70ec5a09a0d5
8166377: is_compiled_by_jvmci hot in some profiles - improve nmethod compiler type detection
neliasso
parents:
39430
diff
changeset
|
41 |
: CodeBlob(name, type, layout, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments), |
38133 | 42 |
_method(method), _mark_for_deoptimization_status(not_marked) { |
43 |
init_defaults(); |
|
44 |
} |
|
45 |
||
42040
70ec5a09a0d5
8166377: is_compiled_by_jvmci hot in some profiles - improve nmethod compiler type detection
neliasso
parents:
39430
diff
changeset
|
46 |
CompiledMethod::CompiledMethod(Method* method, const char* name, CompilerType type, int size, int header_size, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments) |
70ec5a09a0d5
8166377: is_compiled_by_jvmci hot in some profiles - improve nmethod compiler type detection
neliasso
parents:
39430
diff
changeset
|
47 |
: CodeBlob(name, type, CodeBlobLayout((address) this, size, header_size, cb), cb, frame_complete_offset, frame_size, oop_maps, caller_must_gc_arguments), |
38133 | 48 |
_method(method), _mark_for_deoptimization_status(not_marked) { |
49 |
init_defaults(); |
|
50 |
} |
|
51 |
||
52 |
void CompiledMethod::init_defaults() { |
|
53 |
_has_unsafe_access = 0; |
|
54 |
_has_method_handle_invokes = 0; |
|
55 |
_lazy_critical_native = 0; |
|
56 |
_has_wide_vectors = 0; |
|
57 |
_unloading_clock = 0; |
|
58 |
} |
|
59 |
||
60 |
bool CompiledMethod::is_method_handle_return(address return_pc) { |
|
61 |
if (!has_method_handle_invokes()) return false; |
|
62 |
PcDesc* pd = pc_desc_at(return_pc); |
|
63 |
if (pd == NULL) |
|
64 |
return false; |
|
65 |
return pd->is_method_handle_invoke(); |
|
66 |
} |
|
67 |
||
68 |
// Returns a string version of the method state. |
|
69 |
const char* CompiledMethod::state() const { |
|
70 |
int state = get_state(); |
|
71 |
switch (state) { |
|
48007
ab3959df2115
8043070: nmethod::verify_interrupt_point() shouldn't enter safepoint
iveresov
parents:
47687
diff
changeset
|
72 |
case not_installed: |
ab3959df2115
8043070: nmethod::verify_interrupt_point() shouldn't enter safepoint
iveresov
parents:
47687
diff
changeset
|
73 |
return "not installed"; |
38133 | 74 |
case in_use: |
75 |
return "in use"; |
|
76 |
case not_used: |
|
77 |
return "not_used"; |
|
78 |
case not_entrant: |
|
79 |
return "not_entrant"; |
|
80 |
case zombie: |
|
81 |
return "zombie"; |
|
82 |
case unloaded: |
|
83 |
return "unloaded"; |
|
84 |
default: |
|
85 |
fatal("unexpected method state: %d", state); |
|
86 |
return NULL; |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
//----------------------------------------------------------------------------- |
|
91 |
||
92 |
void CompiledMethod::add_exception_cache_entry(ExceptionCache* new_entry) { |
|
93 |
assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock"); |
|
94 |
assert(new_entry != NULL,"Must be non null"); |
|
95 |
assert(new_entry->next() == NULL, "Must be null"); |
|
96 |
||
97 |
ExceptionCache *ec = exception_cache(); |
|
98 |
if (ec != NULL) { |
|
99 |
new_entry->set_next(ec); |
|
100 |
} |
|
101 |
release_set_exception_cache(new_entry); |
|
102 |
} |
|
103 |
||
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
104 |
void CompiledMethod::clean_exception_cache() { |
38133 | 105 |
ExceptionCache* prev = NULL; |
106 |
ExceptionCache* curr = exception_cache(); |
|
107 |
||
108 |
while (curr != NULL) { |
|
109 |
ExceptionCache* next = curr->next(); |
|
110 |
||
111 |
Klass* ex_klass = curr->exception_type(); |
|
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
112 |
if (ex_klass != NULL && !ex_klass->is_loader_alive()) { |
38133 | 113 |
if (prev == NULL) { |
114 |
set_exception_cache(next); |
|
115 |
} else { |
|
116 |
prev->set_next(next); |
|
117 |
} |
|
118 |
delete curr; |
|
119 |
// prev stays the same. |
|
120 |
} else { |
|
121 |
prev = curr; |
|
122 |
} |
|
123 |
||
124 |
curr = next; |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
// public method for accessing the exception cache |
|
129 |
// These are the public access methods. |
|
130 |
address CompiledMethod::handler_for_exception_and_pc(Handle exception, address pc) { |
|
131 |
// We never grab a lock to read the exception cache, so we may |
|
132 |
// have false negatives. This is okay, as it can only happen during |
|
133 |
// the first few exception lookups for a given nmethod. |
|
134 |
ExceptionCache* ec = exception_cache(); |
|
135 |
while (ec != NULL) { |
|
136 |
address ret_val; |
|
137 |
if ((ret_val = ec->match(exception,pc)) != NULL) { |
|
138 |
return ret_val; |
|
139 |
} |
|
140 |
ec = ec->next(); |
|
141 |
} |
|
142 |
return NULL; |
|
143 |
} |
|
144 |
||
145 |
void CompiledMethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) { |
|
146 |
// There are potential race conditions during exception cache updates, so we |
|
147 |
// must own the ExceptionCache_lock before doing ANY modifications. Because |
|
148 |
// we don't lock during reads, it is possible to have several threads attempt |
|
149 |
// to update the cache with the same data. We need to check for already inserted |
|
150 |
// copies of the current data before adding it. |
|
151 |
||
152 |
MutexLocker ml(ExceptionCache_lock); |
|
153 |
ExceptionCache* target_entry = exception_cache_entry_for_exception(exception); |
|
154 |
||
155 |
if (target_entry == NULL || !target_entry->add_address_and_handler(pc,handler)) { |
|
156 |
target_entry = new ExceptionCache(exception,pc,handler); |
|
157 |
add_exception_cache_entry(target_entry); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
//-------------end of code for ExceptionCache-------------- |
|
162 |
||
163 |
// private method for handling exception cache |
|
164 |
// These methods are private, and used to manipulate the exception cache |
|
165 |
// directly. |
|
166 |
ExceptionCache* CompiledMethod::exception_cache_entry_for_exception(Handle exception) { |
|
167 |
ExceptionCache* ec = exception_cache(); |
|
168 |
while (ec != NULL) { |
|
169 |
if (ec->match_exception_with_space(exception)) { |
|
170 |
return ec; |
|
171 |
} |
|
172 |
ec = ec->next(); |
|
173 |
} |
|
174 |
return NULL; |
|
175 |
} |
|
176 |
||
177 |
bool CompiledMethod::is_at_poll_return(address pc) { |
|
178 |
RelocIterator iter(this, pc, pc+1); |
|
179 |
while (iter.next()) { |
|
180 |
if (iter.type() == relocInfo::poll_return_type) |
|
181 |
return true; |
|
182 |
} |
|
183 |
return false; |
|
184 |
} |
|
185 |
||
186 |
||
187 |
bool CompiledMethod::is_at_poll_or_poll_return(address pc) { |
|
188 |
RelocIterator iter(this, pc, pc+1); |
|
189 |
while (iter.next()) { |
|
190 |
relocInfo::relocType t = iter.type(); |
|
191 |
if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) |
|
192 |
return true; |
|
193 |
} |
|
194 |
return false; |
|
195 |
} |
|
196 |
||
197 |
void CompiledMethod::verify_oop_relocations() { |
|
198 |
// Ensure sure that the code matches the current oop values |
|
199 |
RelocIterator iter(this, NULL, NULL); |
|
200 |
while (iter.next()) { |
|
201 |
if (iter.type() == relocInfo::oop_type) { |
|
202 |
oop_Relocation* reloc = iter.oop_reloc(); |
|
203 |
if (!reloc->oop_is_immediate()) { |
|
204 |
reloc->verify_oop_relocation(); |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
||
211 |
ScopeDesc* CompiledMethod::scope_desc_at(address pc) { |
|
212 |
PcDesc* pd = pc_desc_at(pc); |
|
213 |
guarantee(pd != NULL, "scope must be present"); |
|
214 |
return new ScopeDesc(this, pd->scope_decode_offset(), |
|
215 |
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), |
|
216 |
pd->return_oop()); |
|
217 |
} |
|
218 |
||
46796 | 219 |
ScopeDesc* CompiledMethod::scope_desc_near(address pc) { |
220 |
PcDesc* pd = pc_desc_near(pc); |
|
221 |
guarantee(pd != NULL, "scope must be present"); |
|
222 |
return new ScopeDesc(this, pd->scope_decode_offset(), |
|
223 |
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), |
|
224 |
pd->return_oop()); |
|
225 |
} |
|
226 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
227 |
address CompiledMethod::oops_reloc_begin() const { |
38133 | 228 |
// If the method is not entrant or zombie then a JMP is plastered over the |
229 |
// first few bytes. If an oop in the old code was there, that oop |
|
230 |
// should not get GC'd. Skip the first few bytes of oops on |
|
231 |
// not-entrant methods. |
|
232 |
address low_boundary = verified_entry_point(); |
|
233 |
if (!is_in_use() && is_nmethod()) { |
|
234 |
low_boundary += NativeJump::instruction_size; |
|
235 |
// %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. |
|
236 |
// This means that the low_boundary is going to be a little too high. |
|
237 |
// This shouldn't matter, since oops of non-entrant methods are never used. |
|
238 |
// In fact, why are we bothering to look at oops in a non-entrant method?? |
|
239 |
} |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
240 |
return low_boundary; |
38133 | 241 |
} |
242 |
||
243 |
int CompiledMethod::verify_icholder_relocations() { |
|
244 |
ResourceMark rm; |
|
245 |
int count = 0; |
|
246 |
||
247 |
RelocIterator iter(this); |
|
248 |
while(iter.next()) { |
|
249 |
if (iter.type() == relocInfo::virtual_call_type) { |
|
42650 | 250 |
if (CompiledIC::is_icholder_call_site(iter.virtual_call_reloc(), this)) { |
38133 | 251 |
CompiledIC *ic = CompiledIC_at(&iter); |
252 |
if (TraceCompiledIC) { |
|
253 |
tty->print("noticed icholder " INTPTR_FORMAT " ", p2i(ic->cached_icholder())); |
|
254 |
ic->print(); |
|
255 |
} |
|
256 |
assert(ic->cached_icholder() != NULL, "must be non-NULL"); |
|
257 |
count++; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
||
262 |
return count; |
|
263 |
} |
|
264 |
||
265 |
// Method that knows how to preserve outgoing arguments at call. This method must be |
|
266 |
// called with a frame corresponding to a Java invoke |
|
267 |
void CompiledMethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { |
|
268 |
if (method() != NULL && !method()->is_native()) { |
|
269 |
address pc = fr.pc(); |
|
270 |
SimpleScopeDesc ssd(this, pc); |
|
271 |
Bytecode_invoke call(ssd.method(), ssd.bci()); |
|
272 |
bool has_receiver = call.has_receiver(); |
|
273 |
bool has_appendix = call.has_appendix(); |
|
274 |
Symbol* signature = call.signature(); |
|
275 |
||
276 |
// The method attached by JIT-compilers should be used, if present. |
|
277 |
// Bytecode can be inaccurate in such case. |
|
278 |
Method* callee = attached_method_before_pc(pc); |
|
279 |
if (callee != NULL) { |
|
280 |
has_receiver = !(callee->access_flags().is_static()); |
|
281 |
has_appendix = false; |
|
282 |
signature = callee->signature(); |
|
283 |
} |
|
284 |
||
285 |
fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f); |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
Method* CompiledMethod::attached_method(address call_instr) { |
|
290 |
assert(code_contains(call_instr), "not part of the nmethod"); |
|
291 |
RelocIterator iter(this, call_instr, call_instr + 1); |
|
292 |
while (iter.next()) { |
|
293 |
if (iter.addr() == call_instr) { |
|
294 |
switch(iter.type()) { |
|
295 |
case relocInfo::static_call_type: return iter.static_call_reloc()->method_value(); |
|
296 |
case relocInfo::opt_virtual_call_type: return iter.opt_virtual_call_reloc()->method_value(); |
|
297 |
case relocInfo::virtual_call_type: return iter.virtual_call_reloc()->method_value(); |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
298 |
default: break; |
38133 | 299 |
} |
300 |
} |
|
301 |
} |
|
302 |
return NULL; // not found |
|
303 |
} |
|
304 |
||
305 |
Method* CompiledMethod::attached_method_before_pc(address pc) { |
|
306 |
if (NativeCall::is_call_before(pc)) { |
|
307 |
NativeCall* ncall = nativeCall_before(pc); |
|
308 |
return attached_method(ncall->instruction_address()); |
|
309 |
} |
|
310 |
return NULL; // not a call |
|
311 |
} |
|
312 |
||
313 |
void CompiledMethod::clear_inline_caches() { |
|
314 |
assert(SafepointSynchronize::is_at_safepoint(), "cleaning of IC's only allowed at safepoint"); |
|
315 |
if (is_zombie()) { |
|
316 |
return; |
|
317 |
} |
|
318 |
||
319 |
RelocIterator iter(this); |
|
320 |
while (iter.next()) { |
|
321 |
iter.reloc()->clear_inline_cache(); |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
// Clear ICStubs of all compiled ICs |
|
326 |
void CompiledMethod::clear_ic_stubs() { |
|
327 |
assert_locked_or_safepoint(CompiledIC_lock); |
|
328 |
RelocIterator iter(this); |
|
329 |
while(iter.next()) { |
|
330 |
if (iter.type() == relocInfo::virtual_call_type) { |
|
331 |
CompiledIC* ic = CompiledIC_at(&iter); |
|
332 |
ic->clear_ic_stub(); |
|
333 |
} |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
#ifdef ASSERT |
|
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
338 |
// Check class_loader is alive for this bit of metadata. |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
339 |
static void check_class(Metadata* md) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
340 |
Klass* klass = NULL; |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
341 |
if (md->is_klass()) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
342 |
klass = ((Klass*)md); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
343 |
} else if (md->is_method()) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
344 |
klass = ((Method*)md)->method_holder(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
345 |
} else if (md->is_methodData()) { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
346 |
klass = ((MethodData*)md)->method()->method_holder(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
347 |
} else { |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
348 |
md->print(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
349 |
ShouldNotReachHere(); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
350 |
} |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
351 |
assert(klass->is_loader_alive(), "must be alive"); |
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
352 |
} |
38133 | 353 |
#endif // ASSERT |
354 |
||
42650 | 355 |
|
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
356 |
void CompiledMethod::clean_ic_if_metadata_is_dead(CompiledIC *ic) { |
38133 | 357 |
if (ic->is_icholder_call()) { |
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
358 |
// The only exception is compiledICHolder metdata which may |
38133 | 359 |
// yet be marked below. (We check this further below). |
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
360 |
CompiledICHolder* cichk_metdata = ic->cached_icholder(); |
38133 | 361 |
|
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
362 |
if (cichk_metdata->is_loader_alive()) { |
38133 | 363 |
return; |
364 |
} |
|
365 |
} else { |
|
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
366 |
Metadata* ic_metdata = ic->cached_metadata(); |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
367 |
if (ic_metdata != NULL) { |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
368 |
if (ic_metdata->is_klass()) { |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
369 |
if (((Klass*)ic_metdata)->is_loader_alive()) { |
38133 | 370 |
return; |
371 |
} |
|
49969
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
372 |
} else if (ic_metdata->is_method()) { |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
373 |
Method* method = (Method*)ic_metdata; |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
374 |
assert(!method->is_old(), "old method should have been cleaned"); |
8624981f1ffa
8202447: Fix unloading_occurred to mean unloading_occurred
coleenp
parents:
49890
diff
changeset
|
375 |
if (method->method_holder()->is_loader_alive()) { |
38133 | 376 |
return; |
377 |
} |
|
378 |
} else { |
|
379 |
ShouldNotReachHere(); |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
ic->set_to_clean(); |
|
385 |
} |
|
386 |
||
387 |
unsigned char CompiledMethod::_global_unloading_clock = 0; |
|
388 |
||
389 |
void CompiledMethod::increase_unloading_clock() { |
|
390 |
_global_unloading_clock++; |
|
391 |
if (_global_unloading_clock == 0) { |
|
392 |
// _nmethods are allocated with _unloading_clock == 0, |
|
393 |
// so 0 is never used as a clock value. |
|
394 |
_global_unloading_clock = 1; |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
void CompiledMethod::set_unloading_clock(unsigned char unloading_clock) { |
|
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48557
diff
changeset
|
399 |
OrderAccess::release_store(&_unloading_clock, unloading_clock); |
38133 | 400 |
} |
401 |
||
402 |
unsigned char CompiledMethod::unloading_clock() { |
|
48955
e22914003cf0
8194691: Cleanup unnecessary casts in Atomic/OrderAccess uses
kbarrett
parents:
48557
diff
changeset
|
403 |
return OrderAccess::load_acquire(&_unloading_clock); |
38133 | 404 |
} |
405 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
406 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
407 |
// static_stub_Relocations may have dangling references to |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
408 |
// nmethods so trim them out here. Otherwise it looks like |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
409 |
// compiled code is maintaining a link to dead metadata. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
410 |
void CompiledMethod::clean_ic_stubs() { |
38133 | 411 |
#ifdef ASSERT |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
412 |
address low_boundary = oops_reloc_begin(); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
413 |
RelocIterator iter(this, low_boundary); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
414 |
while (iter.next()) { |
38133 | 415 |
address static_call_addr = NULL; |
416 |
if (iter.type() == relocInfo::opt_virtual_call_type) { |
|
417 |
CompiledIC* cic = CompiledIC_at(&iter); |
|
418 |
if (!cic->is_call_to_interpreted()) { |
|
419 |
static_call_addr = iter.addr(); |
|
420 |
} |
|
421 |
} else if (iter.type() == relocInfo::static_call_type) { |
|
422 |
CompiledStaticCall* csc = compiledStaticCall_at(iter.reloc()); |
|
423 |
if (!csc->is_call_to_interpreted()) { |
|
424 |
static_call_addr = iter.addr(); |
|
425 |
} |
|
426 |
} |
|
427 |
if (static_call_addr != NULL) { |
|
428 |
RelocIterator sciter(this, low_boundary); |
|
429 |
while (sciter.next()) { |
|
430 |
if (sciter.type() == relocInfo::static_stub_type && |
|
431 |
sciter.static_stub_reloc()->static_call() == static_call_addr) { |
|
432 |
sciter.static_stub_reloc()->clear_inline_cache(); |
|
433 |
} |
|
434 |
} |
|
435 |
} |
|
436 |
} |
|
437 |
#endif |
|
438 |
} |
|
439 |
||
440 |
// This is called at the end of the strong tracing/marking phase of a |
|
441 |
// GC to unload an nmethod if it contains otherwise unreachable |
|
442 |
// oops. |
|
443 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
444 |
void CompiledMethod::do_unloading(BoolObjectClosure* is_alive) { |
38133 | 445 |
// Make sure the oop's ready to receive visitors |
446 |
assert(!is_zombie() && !is_unloaded(), |
|
447 |
"should not call follow on zombie or unloaded nmethod"); |
|
448 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
449 |
address low_boundary = oops_reloc_begin(); |
38133 | 450 |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
451 |
if (do_unloading_oops(low_boundary, is_alive)) { |
38133 | 452 |
return; |
453 |
} |
|
454 |
||
455 |
#if INCLUDE_JVMCI |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
456 |
if (do_unloading_jvmci()) { |
38133 | 457 |
return; |
458 |
} |
|
459 |
#endif |
|
460 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
461 |
// Cleanup exception cache and inline caches happens |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
462 |
// after all the unloaded methods are found. |
38133 | 463 |
} |
464 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
465 |
// Clean references to unloaded nmethods at addr from this one, which is not unloaded. |
38133 | 466 |
template <class CompiledICorStaticCall> |
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
467 |
static bool clean_if_nmethod_is_unloaded(CompiledICorStaticCall *ic, address addr, CompiledMethod* from, |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
468 |
bool parallel, bool clean_all) { |
38133 | 469 |
// Ok, to lookup references to zombies here |
470 |
CodeBlob *cb = CodeCache::find_blob_unsafe(addr); |
|
471 |
CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL; |
|
472 |
if (nm != NULL) { |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
473 |
if (parallel && nm->unloading_clock() != CompiledMethod::global_unloading_clock()) { |
38133 | 474 |
// The nmethod has not been processed yet. |
475 |
return true; |
|
476 |
} |
|
477 |
||
478 |
// Clean inline caches pointing to both zombie and not_entrant methods |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
479 |
if (clean_all || !nm->is_in_use() || (nm->method()->code() != nm)) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
480 |
ic->set_to_clean(from->is_alive()); |
38133 | 481 |
assert(ic->is_clean(), "nmethod " PTR_FORMAT "not clean %s", p2i(from), from->method()->name_and_sig_as_C_string()); |
482 |
} |
|
483 |
} |
|
484 |
||
485 |
return false; |
|
486 |
} |
|
487 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
488 |
static bool clean_if_nmethod_is_unloaded(CompiledIC *ic, CompiledMethod* from, |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
489 |
bool parallel, bool clean_all = false) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
490 |
return clean_if_nmethod_is_unloaded(ic, ic->ic_destination(), from, parallel, clean_all); |
38133 | 491 |
} |
492 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
493 |
static bool clean_if_nmethod_is_unloaded(CompiledStaticCall *csc, CompiledMethod* from, |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
494 |
bool parallel, bool clean_all = false) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
495 |
return clean_if_nmethod_is_unloaded(csc, csc->destination(), from, parallel, clean_all); |
38133 | 496 |
} |
497 |
||
498 |
bool CompiledMethod::do_unloading_parallel(BoolObjectClosure* is_alive, bool unloading_occurred) { |
|
499 |
ResourceMark rm; |
|
500 |
||
501 |
// Make sure the oop's ready to receive visitors |
|
502 |
assert(!is_zombie() && !is_unloaded(), |
|
503 |
"should not call follow on zombie or unloaded nmethod"); |
|
504 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
505 |
address low_boundary = oops_reloc_begin(); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
506 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
507 |
if (do_unloading_oops(low_boundary, is_alive)) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
508 |
return false; |
38133 | 509 |
} |
510 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
511 |
#if INCLUDE_JVMCI |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
512 |
if (do_unloading_jvmci()) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
513 |
return false; |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
514 |
} |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
515 |
#endif |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
516 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
517 |
return unload_nmethod_caches(/*parallel*/true, unloading_occurred); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
518 |
} |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
519 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
520 |
// Cleans caches in nmethods that point to either classes that are unloaded |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
521 |
// or nmethods that are unloaded. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
522 |
// |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
523 |
// Can be called either in parallel by G1 currently or after all |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
524 |
// nmethods are unloaded. Return postponed=true in the parallel case for |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
525 |
// inline caches found that point to nmethods that are not yet visited during |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
526 |
// the do_unloading walk. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
527 |
bool CompiledMethod::unload_nmethod_caches(bool parallel, bool unloading_occurred) { |
38133 | 528 |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
529 |
// Exception cache only needs to be called if unloading occurred |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
530 |
if (unloading_occurred) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
531 |
clean_exception_cache(); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
532 |
} |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
533 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
534 |
bool postponed = cleanup_inline_caches_impl(parallel, unloading_occurred, /*clean_all*/false); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
535 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
536 |
// All static stubs need to be cleaned. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
537 |
clean_ic_stubs(); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
538 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
539 |
// Check that the metadata embedded in the nmethod is alive |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
540 |
DEBUG_ONLY(metadata_do(check_class)); |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
541 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
542 |
return postponed; |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
543 |
} |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
544 |
|
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
545 |
// Called to clean up after class unloading for live nmethods and from the sweeper |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
546 |
// for all methods. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
547 |
bool CompiledMethod::cleanup_inline_caches_impl(bool parallel, bool unloading_occurred, bool clean_all) { |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
548 |
assert_locked_or_safepoint(CompiledIC_lock); |
38133 | 549 |
bool postponed = false; |
550 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
551 |
// Find all calls in an nmethod and clear the ones that point to non-entrant, |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
552 |
// zombie and unloaded nmethods. |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
553 |
RelocIterator iter(this, oops_reloc_begin()); |
38133 | 554 |
while(iter.next()) { |
555 |
||
556 |
switch (iter.type()) { |
|
557 |
||
558 |
case relocInfo::virtual_call_type: |
|
559 |
if (unloading_occurred) { |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
560 |
// If class unloading occurred we first clear ICs where the cached metadata |
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
561 |
// is referring to an unloaded klass or method. |
49821
02c08e20d66c
8201537: Remove is_alive closure from Klass::is_loader_alive()
coleenp
parents:
49480
diff
changeset
|
562 |
clean_ic_if_metadata_is_dead(CompiledIC_at(&iter)); |
38133 | 563 |
} |
564 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
565 |
postponed |= clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, parallel, clean_all); |
38133 | 566 |
break; |
567 |
||
568 |
case relocInfo::opt_virtual_call_type: |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
569 |
postponed |= clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, parallel, clean_all); |
38133 | 570 |
break; |
571 |
||
572 |
case relocInfo::static_call_type: |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
573 |
postponed |= clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), this, parallel, clean_all); |
38133 | 574 |
break; |
575 |
||
576 |
case relocInfo::oop_type: |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
577 |
// handled by do_unloading_oops already |
38133 | 578 |
break; |
579 |
||
580 |
case relocInfo::metadata_type: |
|
581 |
break; // nothing to do. |
|
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
582 |
|
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
583 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
584 |
break; |
38133 | 585 |
} |
586 |
} |
|
587 |
||
588 |
return postponed; |
|
589 |
} |
|
590 |
||
49890
29b94ed63a09
8202164: Remove some unneeded BoolObjectClosure* is_alive parameters
coleenp
parents:
49821
diff
changeset
|
591 |
void CompiledMethod::do_unloading_parallel_postponed() { |
38133 | 592 |
ResourceMark rm; |
593 |
||
594 |
// Make sure the oop's ready to receive visitors |
|
595 |
assert(!is_zombie(), |
|
596 |
"should not call follow on zombie nmethod"); |
|
597 |
||
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
598 |
RelocIterator iter(this, oops_reloc_begin()); |
38133 | 599 |
while(iter.next()) { |
600 |
||
601 |
switch (iter.type()) { |
|
602 |
||
603 |
case relocInfo::virtual_call_type: |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
604 |
clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, true); |
38133 | 605 |
break; |
606 |
||
607 |
case relocInfo::opt_virtual_call_type: |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
608 |
clean_if_nmethod_is_unloaded(CompiledIC_at(&iter), this, true); |
38133 | 609 |
break; |
610 |
||
611 |
case relocInfo::static_call_type: |
|
50416
ef980b9ac191
8203837: Split nmethod unloading from inline cache cleaning
coleenp
parents:
49969
diff
changeset
|
612 |
clean_if_nmethod_is_unloaded(compiledStaticCall_at(iter.reloc()), this, true); |
38133 | 613 |
break; |
46630
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
614 |
|
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
615 |
default: |
75aa3e39d02c
8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents:
46623
diff
changeset
|
616 |
break; |
38133 | 617 |
} |
618 |
} |
|
619 |
} |