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