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