Mercurial > hg > truffle
annotate src/share/vm/code/nmethod.cpp @ 7386:707e9cca11de
fixed HotSpot windows build
fixed Thread.isInterrupted() slowcase
author | Christian Haeubl <haeubl@ssw.jku.at> |
---|---|
date | Tue, 18 Dec 2012 15:05:58 +0100 |
parents | 5d0bb7d52783 |
children | 0b646334c5f7 |
rev | line source |
---|---|
7066 | 1 /* |
2 * Copyright (c) 1997, 2012, 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/codeCache.hpp" | |
27 #include "code/compiledIC.hpp" | |
28 #include "code/dependencies.hpp" | |
29 #include "code/nmethod.hpp" | |
30 #include "code/scopeDesc.hpp" | |
31 #include "compiler/abstractCompiler.hpp" | |
32 #include "compiler/compileBroker.hpp" | |
33 #include "compiler/compileLog.hpp" | |
34 #include "compiler/compilerOracle.hpp" | |
35 #include "compiler/disassembler.hpp" | |
36 #include "interpreter/bytecode.hpp" | |
37 #include "oops/methodData.hpp" | |
38 #include "prims/jvmtiRedefineClassesTrace.hpp" | |
39 #include "prims/jvmtiImpl.hpp" | |
40 #include "runtime/sharedRuntime.hpp" | |
41 #include "runtime/sweeper.hpp" | |
42 #include "utilities/dtrace.hpp" | |
43 #include "utilities/events.hpp" | |
44 #include "utilities/xmlstream.hpp" | |
45 #include "utilities/debug.hpp" | |
46 #include "utilities/machineCodePrinter.hpp" | |
47 #ifdef SHARK | |
48 #include "shark/sharkCompiler.hpp" | |
49 #endif | |
50 #ifdef GRAAL | |
51 #include "graal/graalJavaAccess.hpp" | |
52 #endif | |
53 | |
54 #ifdef DTRACE_ENABLED | |
55 | |
56 // Only bother with this argument setup if dtrace is available | |
57 | |
58 #ifndef USDT2 | |
59 HS_DTRACE_PROBE_DECL8(hotspot, compiled__method__load, | |
60 const char*, int, const char*, int, const char*, int, void*, size_t); | |
61 | |
62 HS_DTRACE_PROBE_DECL6(hotspot, compiled__method__unload, | |
63 char*, int, char*, int, char*, int); | |
64 | |
65 #define DTRACE_METHOD_UNLOAD_PROBE(method) \ | |
66 { \ | |
67 Method* m = (method); \ | |
68 if (m != NULL) { \ | |
69 Symbol* klass_name = m->klass_name(); \ | |
70 Symbol* name = m->name(); \ | |
71 Symbol* signature = m->signature(); \ | |
72 HS_DTRACE_PROBE6(hotspot, compiled__method__unload, \ | |
73 klass_name->bytes(), klass_name->utf8_length(), \ | |
74 name->bytes(), name->utf8_length(), \ | |
75 signature->bytes(), signature->utf8_length()); \ | |
76 } \ | |
77 } | |
78 #else /* USDT2 */ | |
79 #define DTRACE_METHOD_UNLOAD_PROBE(method) \ | |
80 { \ | |
81 Method* m = (method); \ | |
82 if (m != NULL) { \ | |
83 Symbol* klass_name = m->klass_name(); \ | |
84 Symbol* name = m->name(); \ | |
85 Symbol* signature = m->signature(); \ | |
86 HOTSPOT_COMPILED_METHOD_UNLOAD( \ | |
87 (char *) klass_name->bytes(), klass_name->utf8_length(), \ | |
88 (char *) name->bytes(), name->utf8_length(), \ | |
89 (char *) signature->bytes(), signature->utf8_length()); \ | |
90 } \ | |
91 } | |
92 #endif /* USDT2 */ | |
93 | |
94 #else // ndef DTRACE_ENABLED | |
95 | |
96 #define DTRACE_METHOD_UNLOAD_PROBE(method) | |
97 | |
98 #endif | |
99 | |
100 bool nmethod::is_compiled_by_c1() const { | |
101 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing | |
102 if (is_native_method()) return false; | |
103 return compiler()->is_c1(); | |
104 } | |
7125
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
105 bool nmethod::is_compiled_by_graal() const { |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
106 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
107 if (is_native_method()) return false; |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
108 return compiler()->is_graal(); |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
109 } |
7066 | 110 bool nmethod::is_compiled_by_c2() const { |
111 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing | |
112 if (is_native_method()) return false; | |
113 return compiler()->is_c2(); | |
114 } | |
115 bool nmethod::is_compiled_by_shark() const { | |
116 if (is_native_method()) return false; | |
117 assert(compiler() != NULL, "must be"); | |
118 return compiler()->is_shark(); | |
119 } | |
120 | |
121 | |
122 | |
123 //--------------------------------------------------------------------------------- | |
124 // NMethod statistics | |
125 // They are printed under various flags, including: | |
126 // PrintC1Statistics, PrintOptoStatistics, LogVMOutput, and LogCompilation. | |
127 // (In the latter two cases, they like other stats are printed to the log only.) | |
128 | |
129 // These variables are put into one block to reduce relocations | |
130 // and make it simpler to print from the debugger. | |
131 static | |
132 struct nmethod_stats_struct { | |
133 int nmethod_count; | |
134 int total_size; | |
135 int relocation_size; | |
136 int consts_size; | |
137 int insts_size; | |
138 int stub_size; | |
139 int scopes_data_size; | |
140 int scopes_pcs_size; | |
141 int dependencies_size; | |
142 int handler_table_size; | |
143 int nul_chk_table_size; | |
144 int oops_size; | |
145 | |
146 void note_nmethod(nmethod* nm) { | |
147 nmethod_count += 1; | |
148 total_size += nm->size(); | |
149 relocation_size += nm->relocation_size(); | |
150 consts_size += nm->consts_size(); | |
151 insts_size += nm->insts_size(); | |
152 stub_size += nm->stub_size(); | |
153 oops_size += nm->oops_size(); | |
154 scopes_data_size += nm->scopes_data_size(); | |
155 scopes_pcs_size += nm->scopes_pcs_size(); | |
156 dependencies_size += nm->dependencies_size(); | |
157 handler_table_size += nm->handler_table_size(); | |
158 nul_chk_table_size += nm->nul_chk_table_size(); | |
159 } | |
160 void print_nmethod_stats() { | |
161 if (nmethod_count == 0) return; | |
162 tty->print_cr("Statistics for %d bytecoded nmethods:", nmethod_count); | |
163 if (total_size != 0) tty->print_cr(" total in heap = %d", total_size); | |
164 if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size); | |
165 if (consts_size != 0) tty->print_cr(" constants = %d", consts_size); | |
166 if (insts_size != 0) tty->print_cr(" main code = %d", insts_size); | |
167 if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size); | |
168 if (oops_size != 0) tty->print_cr(" oops = %d", oops_size); | |
169 if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size); | |
170 if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size); | |
171 if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size); | |
172 if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size); | |
173 if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size); | |
174 } | |
175 | |
176 int native_nmethod_count; | |
177 int native_total_size; | |
178 int native_relocation_size; | |
179 int native_insts_size; | |
180 int native_oops_size; | |
181 void note_native_nmethod(nmethod* nm) { | |
182 native_nmethod_count += 1; | |
183 native_total_size += nm->size(); | |
184 native_relocation_size += nm->relocation_size(); | |
185 native_insts_size += nm->insts_size(); | |
186 native_oops_size += nm->oops_size(); | |
187 } | |
188 void print_native_nmethod_stats() { | |
189 if (native_nmethod_count == 0) return; | |
190 tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count); | |
191 if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size); | |
192 if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size); | |
193 if (native_insts_size != 0) tty->print_cr(" N. main code = %d", native_insts_size); | |
194 if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size); | |
195 } | |
196 | |
197 int pc_desc_resets; // number of resets (= number of caches) | |
198 int pc_desc_queries; // queries to nmethod::find_pc_desc | |
199 int pc_desc_approx; // number of those which have approximate true | |
200 int pc_desc_repeats; // number of _pc_descs[0] hits | |
201 int pc_desc_hits; // number of LRU cache hits | |
202 int pc_desc_tests; // total number of PcDesc examinations | |
203 int pc_desc_searches; // total number of quasi-binary search steps | |
204 int pc_desc_adds; // number of LUR cache insertions | |
205 | |
206 void print_pc_stats() { | |
207 tty->print_cr("PcDesc Statistics: %d queries, %.2f comparisons per query", | |
208 pc_desc_queries, | |
209 (double)(pc_desc_tests + pc_desc_searches) | |
210 / pc_desc_queries); | |
211 tty->print_cr(" caches=%d queries=%d/%d, hits=%d+%d, tests=%d+%d, adds=%d", | |
212 pc_desc_resets, | |
213 pc_desc_queries, pc_desc_approx, | |
214 pc_desc_repeats, pc_desc_hits, | |
215 pc_desc_tests, pc_desc_searches, pc_desc_adds); | |
216 } | |
217 } nmethod_stats; | |
218 | |
219 | |
220 //--------------------------------------------------------------------------------- | |
221 | |
222 | |
223 ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) { | |
224 assert(pc != NULL, "Must be non null"); | |
225 assert(exception.not_null(), "Must be non null"); | |
226 assert(handler != NULL, "Must be non null"); | |
227 | |
228 _count = 0; | |
229 _exception_type = exception->klass(); | |
230 _next = NULL; | |
231 | |
232 add_address_and_handler(pc,handler); | |
233 } | |
234 | |
235 | |
236 address ExceptionCache::match(Handle exception, address pc) { | |
237 assert(pc != NULL,"Must be non null"); | |
238 assert(exception.not_null(),"Must be non null"); | |
239 if (exception->klass() == exception_type()) { | |
240 return (test_address(pc)); | |
241 } | |
242 | |
243 return NULL; | |
244 } | |
245 | |
246 | |
247 bool ExceptionCache::match_exception_with_space(Handle exception) { | |
248 assert(exception.not_null(),"Must be non null"); | |
249 if (exception->klass() == exception_type() && count() < cache_size) { | |
250 return true; | |
251 } | |
252 return false; | |
253 } | |
254 | |
255 | |
256 address ExceptionCache::test_address(address addr) { | |
257 for (int i=0; i<count(); i++) { | |
258 if (pc_at(i) == addr) { | |
259 return handler_at(i); | |
260 } | |
261 } | |
262 return NULL; | |
263 } | |
264 | |
265 | |
266 bool ExceptionCache::add_address_and_handler(address addr, address handler) { | |
267 if (test_address(addr) == handler) return true; | |
268 if (count() < cache_size) { | |
269 set_pc_at(count(),addr); | |
270 set_handler_at(count(), handler); | |
271 increment_count(); | |
272 return true; | |
273 } | |
274 return false; | |
275 } | |
276 | |
277 | |
278 // private method for handling exception cache | |
279 // These methods are private, and used to manipulate the exception cache | |
280 // directly. | |
281 ExceptionCache* nmethod::exception_cache_entry_for_exception(Handle exception) { | |
282 ExceptionCache* ec = exception_cache(); | |
283 while (ec != NULL) { | |
284 if (ec->match_exception_with_space(exception)) { | |
285 return ec; | |
286 } | |
287 ec = ec->next(); | |
288 } | |
289 return NULL; | |
290 } | |
291 | |
292 | |
293 //----------------------------------------------------------------------------- | |
294 | |
295 | |
296 // Helper used by both find_pc_desc methods. | |
297 static inline bool match_desc(PcDesc* pc, int pc_offset, bool approximate) { | |
298 NOT_PRODUCT(++nmethod_stats.pc_desc_tests); | |
299 if (!approximate) | |
300 return pc->pc_offset() == pc_offset; | |
301 else | |
302 return (pc-1)->pc_offset() < pc_offset && pc_offset <= pc->pc_offset(); | |
303 } | |
304 | |
305 void PcDescCache::reset_to(PcDesc* initial_pc_desc) { | |
306 if (initial_pc_desc == NULL) { | |
307 _pc_descs[0] = NULL; // native method; no PcDescs at all | |
308 return; | |
309 } | |
310 NOT_PRODUCT(++nmethod_stats.pc_desc_resets); | |
311 // reset the cache by filling it with benign (non-null) values | |
312 assert(initial_pc_desc->pc_offset() < 0, "must be sentinel"); | |
313 for (int i = 0; i < cache_size; i++) | |
314 _pc_descs[i] = initial_pc_desc; | |
315 } | |
316 | |
317 PcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) { | |
318 NOT_PRODUCT(++nmethod_stats.pc_desc_queries); | |
319 NOT_PRODUCT(if (approximate) ++nmethod_stats.pc_desc_approx); | |
320 | |
321 // Note: one might think that caching the most recently | |
322 // read value separately would be a win, but one would be | |
323 // wrong. When many threads are updating it, the cache | |
324 // line it's in would bounce between caches, negating | |
325 // any benefit. | |
326 | |
327 // In order to prevent race conditions do not load cache elements | |
328 // repeatedly, but use a local copy: | |
329 PcDesc* res; | |
330 | |
331 // Step one: Check the most recently added value. | |
332 res = _pc_descs[0]; | |
333 if (res == NULL) return NULL; // native method; no PcDescs at all | |
334 if (match_desc(res, pc_offset, approximate)) { | |
335 NOT_PRODUCT(++nmethod_stats.pc_desc_repeats); | |
336 return res; | |
337 } | |
338 | |
339 // Step two: Check the rest of the LRU cache. | |
340 for (int i = 1; i < cache_size; ++i) { | |
341 res = _pc_descs[i]; | |
342 if (res->pc_offset() < 0) break; // optimization: skip empty cache | |
343 if (match_desc(res, pc_offset, approximate)) { | |
344 NOT_PRODUCT(++nmethod_stats.pc_desc_hits); | |
345 return res; | |
346 } | |
347 } | |
348 | |
349 // Report failure. | |
350 return NULL; | |
351 } | |
352 | |
353 void PcDescCache::add_pc_desc(PcDesc* pc_desc) { | |
354 NOT_PRODUCT(++nmethod_stats.pc_desc_adds); | |
355 // Update the LRU cache by shifting pc_desc forward. | |
356 for (int i = 0; i < cache_size; i++) { | |
357 PcDesc* next = _pc_descs[i]; | |
358 _pc_descs[i] = pc_desc; | |
359 pc_desc = next; | |
360 } | |
361 } | |
362 | |
363 // adjust pcs_size so that it is a multiple of both oopSize and | |
364 // sizeof(PcDesc) (assumes that if sizeof(PcDesc) is not a multiple | |
365 // of oopSize, then 2*sizeof(PcDesc) is) | |
366 static int adjust_pcs_size(int pcs_size) { | |
367 int nsize = round_to(pcs_size, oopSize); | |
368 if ((nsize % sizeof(PcDesc)) != 0) { | |
369 nsize = pcs_size + sizeof(PcDesc); | |
370 } | |
371 assert((nsize % oopSize) == 0, "correct alignment"); | |
372 return nsize; | |
373 } | |
374 | |
375 //----------------------------------------------------------------------------- | |
376 | |
377 | |
378 void nmethod::add_exception_cache_entry(ExceptionCache* new_entry) { | |
379 assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock"); | |
380 assert(new_entry != NULL,"Must be non null"); | |
381 assert(new_entry->next() == NULL, "Must be null"); | |
382 | |
383 if (exception_cache() != NULL) { | |
384 new_entry->set_next(exception_cache()); | |
385 } | |
386 set_exception_cache(new_entry); | |
387 } | |
388 | |
389 void nmethod::remove_from_exception_cache(ExceptionCache* ec) { | |
390 ExceptionCache* prev = NULL; | |
391 ExceptionCache* curr = exception_cache(); | |
392 assert(curr != NULL, "nothing to remove"); | |
393 // find the previous and next entry of ec | |
394 while (curr != ec) { | |
395 prev = curr; | |
396 curr = curr->next(); | |
397 assert(curr != NULL, "ExceptionCache not found"); | |
398 } | |
399 // now: curr == ec | |
400 ExceptionCache* next = curr->next(); | |
401 if (prev == NULL) { | |
402 set_exception_cache(next); | |
403 } else { | |
404 prev->set_next(next); | |
405 } | |
406 delete curr; | |
407 } | |
408 | |
409 | |
410 // public method for accessing the exception cache | |
411 // These are the public access methods. | |
412 address nmethod::handler_for_exception_and_pc(Handle exception, address pc) { | |
413 // We never grab a lock to read the exception cache, so we may | |
414 // have false negatives. This is okay, as it can only happen during | |
415 // the first few exception lookups for a given nmethod. | |
416 ExceptionCache* ec = exception_cache(); | |
417 while (ec != NULL) { | |
418 address ret_val; | |
419 if ((ret_val = ec->match(exception,pc)) != NULL) { | |
420 return ret_val; | |
421 } | |
422 ec = ec->next(); | |
423 } | |
424 return NULL; | |
425 } | |
426 | |
427 | |
428 void nmethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) { | |
429 // There are potential race conditions during exception cache updates, so we | |
430 // must own the ExceptionCache_lock before doing ANY modifications. Because | |
431 // we don't lock during reads, it is possible to have several threads attempt | |
432 // to update the cache with the same data. We need to check for already inserted | |
433 // copies of the current data before adding it. | |
434 | |
435 MutexLocker ml(ExceptionCache_lock); | |
436 ExceptionCache* target_entry = exception_cache_entry_for_exception(exception); | |
437 | |
438 if (target_entry == NULL || !target_entry->add_address_and_handler(pc,handler)) { | |
439 target_entry = new ExceptionCache(exception,pc,handler); | |
440 add_exception_cache_entry(target_entry); | |
441 } | |
442 } | |
443 | |
444 | |
445 //-------------end of code for ExceptionCache-------------- | |
446 | |
447 | |
448 int nmethod::total_size() const { | |
449 return | |
450 consts_size() + | |
451 insts_size() + | |
452 stub_size() + | |
453 scopes_data_size() + | |
454 scopes_pcs_size() + | |
455 handler_table_size() + | |
456 nul_chk_table_size(); | |
457 } | |
458 | |
459 const char* nmethod::compile_kind() const { | |
460 if (is_osr_method()) return "osr"; | |
461 if (method() != NULL && is_native_method()) return "c2n"; | |
462 return NULL; | |
463 } | |
464 | |
465 // Fill in default values for various flag fields | |
466 void nmethod::init_defaults() { | |
467 _state = alive; | |
468 _marked_for_reclamation = 0; | |
469 _has_flushed_dependencies = 0; | |
470 _speculatively_disconnected = 0; | |
471 _has_unsafe_access = 0; | |
472 _has_method_handle_invokes = 0; | |
473 _lazy_critical_native = 0; | |
474 _has_wide_vectors = 0; | |
475 _marked_for_deoptimization = 0; | |
476 _lock_count = 0; | |
477 _stack_traversal_mark = 0; | |
478 _unload_reported = false; // jvmti state | |
479 | |
480 #ifdef ASSERT | |
481 _oops_are_stale = false; | |
482 #endif | |
483 | |
484 _oops_do_mark_link = NULL; | |
485 _jmethod_id = NULL; | |
486 _osr_link = NULL; | |
487 _scavenge_root_link = NULL; | |
488 _scavenge_root_state = 0; | |
489 _saved_nmethod_link = NULL; | |
490 _compiler = NULL; | |
491 #ifdef GRAAL | |
492 _graal_installed_code = NULL; | |
493 #endif | |
494 #ifdef HAVE_DTRACE_H | |
495 _trap_offset = 0; | |
496 #endif // def HAVE_DTRACE_H | |
497 } | |
498 | |
499 | |
500 nmethod* nmethod::new_native_nmethod(methodHandle method, | |
501 int compile_id, | |
502 CodeBuffer *code_buffer, | |
503 int vep_offset, | |
504 int frame_complete, | |
505 int frame_size, | |
506 ByteSize basic_lock_owner_sp_offset, | |
507 ByteSize basic_lock_sp_offset, | |
508 OopMapSet* oop_maps) { | |
509 code_buffer->finalize_oop_references(method); | |
510 // create nmethod | |
511 nmethod* nm = NULL; | |
512 { | |
513 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
514 int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod)); | |
515 CodeOffsets offsets; | |
516 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset); | |
517 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete); | |
518 nm = new (native_nmethod_size) | |
519 nmethod(method(), native_nmethod_size, compile_id, &offsets, | |
520 code_buffer, frame_size, | |
521 basic_lock_owner_sp_offset, basic_lock_sp_offset, | |
522 oop_maps); | |
523 if (nm != NULL) nmethod_stats.note_native_nmethod(nm); | |
524 if (PrintAssembly && nm != NULL) | |
525 Disassembler::decode(nm); | |
526 | |
7062
8c5333c80cfd
increased CompileThreshold to increase reliability of profiling information
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6275
diff
changeset
|
527 if (PrintMachineCodeToFile) { |
8c5333c80cfd
increased CompileThreshold to increase reliability of profiling information
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6275
diff
changeset
|
528 MachineCodePrinter::print(nm); |
7066 | 529 } |
530 } | |
531 // verify nmethod | |
532 debug_only(if (nm) nm->verify();) // might block | |
533 | |
534 if (nm != NULL) { | |
535 nm->log_new_nmethod(); | |
536 } | |
537 | |
538 return nm; | |
539 } | |
540 | |
541 #ifdef HAVE_DTRACE_H | |
542 nmethod* nmethod::new_dtrace_nmethod(methodHandle method, | |
543 CodeBuffer *code_buffer, | |
544 int vep_offset, | |
545 int trap_offset, | |
546 int frame_complete, | |
547 int frame_size) { | |
548 code_buffer->finalize_oop_references(method); | |
549 // create nmethod | |
550 nmethod* nm = NULL; | |
551 { | |
552 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
553 int nmethod_size = allocation_size(code_buffer, sizeof(nmethod)); | |
554 CodeOffsets offsets; | |
555 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset); | |
556 offsets.set_value(CodeOffsets::Dtrace_trap, trap_offset); | |
557 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete); | |
558 | |
559 nm = new (nmethod_size) nmethod(method(), nmethod_size, &offsets, code_buffer, frame_size); | |
560 | |
561 if (nm != NULL) nmethod_stats.note_nmethod(nm); | |
562 if (PrintAssembly && nm != NULL) | |
563 Disassembler::decode(nm); | |
564 } | |
565 // verify nmethod | |
566 debug_only(if (nm) nm->verify();) // might block | |
567 | |
568 if (nm != NULL) { | |
569 nm->log_new_nmethod(); | |
570 } | |
571 | |
572 return nm; | |
573 } | |
574 | |
575 #endif // def HAVE_DTRACE_H | |
576 | |
577 nmethod* nmethod::new_nmethod(methodHandle method, | |
578 int compile_id, | |
579 int entry_bci, | |
580 CodeOffsets* offsets, | |
581 int orig_pc_offset, | |
582 DebugInformationRecorder* debug_info, | |
583 Dependencies* dependencies, | |
584 CodeBuffer* code_buffer, int frame_size, | |
585 OopMapSet* oop_maps, | |
586 ExceptionHandlerTable* handler_table, | |
587 ImplicitExceptionTable* nul_chk_table, | |
588 AbstractCompiler* compiler, | |
589 int comp_level | |
590 #ifdef GRAAL | |
591 , Handle installed_code | |
592 #endif | |
593 ) | |
594 { | |
595 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); | |
596 code_buffer->finalize_oop_references(method); | |
597 // create nmethod | |
598 nmethod* nm = NULL; | |
599 { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
600 int nmethod_size = | |
601 allocation_size(code_buffer, sizeof(nmethod)) | |
602 + adjust_pcs_size(debug_info->pcs_size()) | |
603 + round_to(dependencies->size_in_bytes() , oopSize) | |
604 + round_to(handler_table->size_in_bytes(), oopSize) | |
605 + round_to(nul_chk_table->size_in_bytes(), oopSize) | |
606 + round_to(debug_info->data_size() , oopSize); | |
607 nm = new (nmethod_size) | |
608 nmethod(method(), nmethod_size, compile_id, entry_bci, offsets, | |
609 orig_pc_offset, debug_info, dependencies, code_buffer, frame_size, | |
610 oop_maps, | |
611 handler_table, | |
612 nul_chk_table, | |
613 compiler, | |
614 comp_level | |
615 #ifdef GRAAL | |
616 , installed_code | |
617 #endif | |
618 ); | |
619 if (nm != NULL) { | |
620 // To make dependency checking during class loading fast, record | |
621 // the nmethod dependencies in the classes it is dependent on. | |
622 // This allows the dependency checking code to simply walk the | |
623 // class hierarchy above the loaded class, checking only nmethods | |
624 // which are dependent on those classes. The slow way is to | |
625 // check every nmethod for dependencies which makes it linear in | |
626 // the number of methods compiled. For applications with a lot | |
627 // classes the slow way is too slow. | |
628 for (Dependencies::DepStream deps(nm); deps.next(); ) { | |
629 Klass* klass = deps.context_type(); | |
630 if (klass == NULL) continue; // ignore things like evol_method | |
631 | |
632 // record this nmethod as dependent on this klass | |
633 InstanceKlass::cast(klass)->add_dependent_nmethod(nm); | |
634 } | |
635 } | |
636 if (nm != NULL) nmethod_stats.note_nmethod(nm); | |
637 if (PrintAssembly && nm != NULL) | |
638 Disassembler::decode(nm); | |
639 | |
7088
97d0eae99568
guard against nmethod allocation failure in implementation of PrintMachineCodeToFile option
Doug Simon <doug.simon@oracle.com>
parents:
7066
diff
changeset
|
640 if (nm != NULL && PrintMachineCodeToFile) { |
7062
8c5333c80cfd
increased CompileThreshold to increase reliability of profiling information
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6275
diff
changeset
|
641 MachineCodePrinter::print(nm); |
7066 | 642 } |
643 } | |
644 | |
645 // verify nmethod | |
646 debug_only(if (nm) nm->verify();) // might block | |
647 | |
648 if (nm != NULL) { | |
649 nm->log_new_nmethod(); | |
650 } | |
651 | |
652 // done | |
653 return nm; | |
654 } | |
655 | |
656 | |
657 // For native wrappers | |
658 nmethod::nmethod( | |
659 Method* method, | |
660 int nmethod_size, | |
661 int compile_id, | |
662 CodeOffsets* offsets, | |
663 CodeBuffer* code_buffer, | |
664 int frame_size, | |
665 ByteSize basic_lock_owner_sp_offset, | |
666 ByteSize basic_lock_sp_offset, | |
667 OopMapSet* oop_maps ) | |
668 : CodeBlob("native nmethod", code_buffer, sizeof(nmethod), | |
669 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps), | |
670 _native_receiver_sp_offset(basic_lock_owner_sp_offset), | |
671 _native_basic_lock_sp_offset(basic_lock_sp_offset) | |
672 { | |
673 { | |
674 debug_only(No_Safepoint_Verifier nsv;) | |
675 assert_locked_or_safepoint(CodeCache_lock); | |
676 | |
677 init_defaults(); | |
678 _method = method; | |
679 _entry_bci = InvocationEntryBci; | |
680 // We have no exception handler or deopt handler make the | |
681 // values something that will never match a pc like the nmethod vtable entry | |
682 _exception_offset = 0; | |
683 _deoptimize_offset = 0; | |
684 _deoptimize_mh_offset = 0; | |
685 _orig_pc_offset = 0; | |
686 | |
687 _consts_offset = data_offset(); | |
688 _stub_offset = data_offset(); | |
689 _oops_offset = data_offset(); | |
690 _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); | |
691 _scopes_data_offset = _metadata_offset + round_to(code_buffer->total_metadata_size(), wordSize); | |
692 _scopes_pcs_offset = _scopes_data_offset; | |
693 _dependencies_offset = _scopes_pcs_offset; | |
694 _handler_table_offset = _dependencies_offset; | |
695 _nul_chk_table_offset = _handler_table_offset; | |
696 _nmethod_end_offset = _nul_chk_table_offset; | |
697 _compile_id = compile_id; | |
698 _comp_level = CompLevel_none; | |
699 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); | |
700 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); | |
701 _osr_entry_point = NULL; | |
702 _exception_cache = NULL; | |
703 _pc_desc_cache.reset_to(NULL); | |
704 | |
705 code_buffer->copy_values_to(this); | |
706 if (ScavengeRootsInCode && detect_scavenge_root_oops()) { | |
707 CodeCache::add_scavenge_root_nmethod(this); | |
708 } | |
709 debug_only(verify_scavenge_root_oops()); | |
710 CodeCache::commit(this); | |
711 } | |
712 | |
713 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { | |
714 ttyLocker ttyl; // keep the following output all in one block | |
715 // This output goes directly to the tty, not the compiler log. | |
716 // To enable tools to match it up with the compilation activity, | |
717 // be sure to tag this tty output with the compile ID. | |
718 if (xtty != NULL) { | |
719 xtty->begin_head("print_native_nmethod"); | |
720 xtty->method(_method); | |
721 xtty->stamp(); | |
722 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this); | |
723 } | |
724 // print the header part first | |
725 print(); | |
726 // then print the requested information | |
727 if (PrintNativeNMethods) { | |
728 print_code(); | |
729 if (oop_maps != NULL) { | |
730 oop_maps->print(); | |
731 } | |
732 } | |
733 if (PrintRelocations) { | |
734 print_relocations(); | |
735 } | |
736 if (xtty != NULL) { | |
737 xtty->tail("print_native_nmethod"); | |
738 } | |
739 } | |
740 } | |
741 | |
742 // For dtrace wrappers | |
743 #ifdef HAVE_DTRACE_H | |
744 nmethod::nmethod( | |
745 Method* method, | |
746 int nmethod_size, | |
747 CodeOffsets* offsets, | |
748 CodeBuffer* code_buffer, | |
749 int frame_size) | |
750 : CodeBlob("dtrace nmethod", code_buffer, sizeof(nmethod), | |
751 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, NULL), | |
752 _native_receiver_sp_offset(in_ByteSize(-1)), | |
753 _native_basic_lock_sp_offset(in_ByteSize(-1)) | |
754 { | |
755 { | |
756 debug_only(No_Safepoint_Verifier nsv;) | |
757 assert_locked_or_safepoint(CodeCache_lock); | |
758 | |
759 init_defaults(); | |
760 _method = method; | |
761 _entry_bci = InvocationEntryBci; | |
762 // We have no exception handler or deopt handler make the | |
763 // values something that will never match a pc like the nmethod vtable entry | |
764 _exception_offset = 0; | |
765 _deoptimize_offset = 0; | |
766 _deoptimize_mh_offset = 0; | |
767 _unwind_handler_offset = -1; | |
768 _trap_offset = offsets->value(CodeOffsets::Dtrace_trap); | |
769 _orig_pc_offset = 0; | |
770 _consts_offset = data_offset(); | |
771 _stub_offset = data_offset(); | |
772 _oops_offset = data_offset(); | |
773 _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); | |
774 _scopes_data_offset = _metadata_offset + round_to(code_buffer->total_metadata_size(), wordSize); | |
775 _scopes_pcs_offset = _scopes_data_offset; | |
776 _dependencies_offset = _scopes_pcs_offset; | |
777 _handler_table_offset = _dependencies_offset; | |
778 _nul_chk_table_offset = _handler_table_offset; | |
779 _nmethod_end_offset = _nul_chk_table_offset; | |
780 _compile_id = 0; // default | |
781 _comp_level = CompLevel_none; | |
782 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); | |
783 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); | |
784 _osr_entry_point = NULL; | |
785 _exception_cache = NULL; | |
786 _pc_desc_cache.reset_to(NULL); | |
787 | |
788 code_buffer->copy_values_to(this); | |
789 debug_only(verify_scavenge_root_oops()); | |
790 CodeCache::commit(this); | |
791 } | |
792 | |
793 if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { | |
794 ttyLocker ttyl; // keep the following output all in one block | |
795 // This output goes directly to the tty, not the compiler log. | |
796 // To enable tools to match it up with the compilation activity, | |
797 // be sure to tag this tty output with the compile ID. | |
798 if (xtty != NULL) { | |
799 xtty->begin_head("print_dtrace_nmethod"); | |
800 xtty->method(_method); | |
801 xtty->stamp(); | |
802 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this); | |
803 } | |
804 // print the header part first | |
805 print(); | |
806 // then print the requested information | |
807 if (PrintNMethods) { | |
808 print_code(); | |
809 } | |
810 if (PrintRelocations) { | |
811 print_relocations(); | |
812 } | |
813 if (xtty != NULL) { | |
814 xtty->tail("print_dtrace_nmethod"); | |
815 } | |
816 } | |
817 } | |
818 #endif // def HAVE_DTRACE_H | |
819 | |
820 void* nmethod::operator new(size_t size, int nmethod_size) { | |
821 // Always leave some room in the CodeCache for I2C/C2I adapters | |
822 if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) return NULL; | |
823 return CodeCache::allocate(nmethod_size); | |
824 } | |
825 | |
826 | |
827 nmethod::nmethod( | |
828 Method* method, | |
829 int nmethod_size, | |
830 int compile_id, | |
831 int entry_bci, | |
832 CodeOffsets* offsets, | |
833 int orig_pc_offset, | |
834 DebugInformationRecorder* debug_info, | |
835 Dependencies* dependencies, | |
836 CodeBuffer *code_buffer, | |
837 int frame_size, | |
838 OopMapSet* oop_maps, | |
839 ExceptionHandlerTable* handler_table, | |
840 ImplicitExceptionTable* nul_chk_table, | |
841 AbstractCompiler* compiler, | |
842 int comp_level | |
843 #ifdef GRAAL | |
844 , Handle installed_code | |
845 #endif | |
846 ) | |
847 : CodeBlob("nmethod", code_buffer, sizeof(nmethod), | |
848 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps), | |
849 _native_receiver_sp_offset(in_ByteSize(-1)), | |
850 _native_basic_lock_sp_offset(in_ByteSize(-1)) | |
851 { | |
852 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); | |
853 { | |
854 debug_only(No_Safepoint_Verifier nsv;) | |
855 assert_locked_or_safepoint(CodeCache_lock); | |
856 | |
857 init_defaults(); | |
858 _method = method; | |
859 _entry_bci = entry_bci; | |
860 _compile_id = compile_id; | |
861 _comp_level = comp_level; | |
862 _compiler = compiler; | |
863 _orig_pc_offset = orig_pc_offset; | |
864 | |
865 // Section offsets | |
866 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); | |
867 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); | |
868 | |
869 #ifdef GRAAL | |
870 _graal_installed_code = installed_code(); | |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
871 #endif |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
872 if (compiler->is_graal()) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
873 // Graal might not produce any stub sections |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
874 if (offsets->value(CodeOffsets::Exceptions) != -1) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
875 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
876 } else { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
877 _exception_offset = -1; |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
878 } |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
879 if (offsets->value(CodeOffsets::Deopt) != -1) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
880 _deoptimize_offset = code_offset() + offsets->value(CodeOffsets::Deopt); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
881 } else { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
882 _deoptimize_offset = -1; |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
883 } |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
884 if (offsets->value(CodeOffsets::DeoptMH) != -1) { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
885 _deoptimize_mh_offset = code_offset() + offsets->value(CodeOffsets::DeoptMH); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
886 } else { |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
887 _deoptimize_mh_offset = -1; |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
888 } |
7066 | 889 } else { |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
890 // Exception handler and deopt handler are in the stub section |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
891 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set"); |
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
892 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set"); |
7066 | 893 |
894 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions); | |
895 _deoptimize_offset = _stub_offset + offsets->value(CodeOffsets::Deopt); | |
896 if (offsets->value(CodeOffsets::DeoptMH) != -1) { | |
897 _deoptimize_mh_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH); | |
898 } else { | |
899 _deoptimize_mh_offset = -1; | |
900 } | |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
901 } |
7066 | 902 if (offsets->value(CodeOffsets::UnwindHandler) != -1) { |
903 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler); | |
904 } else { | |
905 _unwind_handler_offset = -1; | |
906 } | |
907 | |
908 _oops_offset = data_offset(); | |
909 _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); | |
910 _scopes_data_offset = _metadata_offset + round_to(code_buffer->total_metadata_size(), wordSize); | |
911 | |
912 _scopes_pcs_offset = _scopes_data_offset + round_to(debug_info->data_size (), oopSize); | |
913 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size()); | |
914 _handler_table_offset = _dependencies_offset + round_to(dependencies->size_in_bytes (), oopSize); | |
915 _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize); | |
916 _nmethod_end_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize); | |
917 | |
918 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); | |
919 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); | |
920 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry); | |
921 _exception_cache = NULL; | |
922 _pc_desc_cache.reset_to(scopes_pcs_begin()); | |
923 | |
924 // Copy contents of ScopeDescRecorder to nmethod | |
925 code_buffer->copy_values_to(this); | |
926 debug_info->copy_to(this); | |
927 dependencies->copy_to(this); | |
928 if (ScavengeRootsInCode && detect_scavenge_root_oops()) { | |
929 CodeCache::add_scavenge_root_nmethod(this); | |
930 } | |
931 debug_only(verify_scavenge_root_oops()); | |
932 | |
933 CodeCache::commit(this); | |
934 | |
935 // Copy contents of ExceptionHandlerTable to nmethod | |
936 handler_table->copy_to(this); | |
937 nul_chk_table->copy_to(this); | |
938 | |
939 // we use the information of entry points to find out if a method is | |
940 // static or non static | |
941 assert(compiler->is_c2() || | |
942 _method->is_static() == (entry_point() == _verified_entry_point), | |
943 " entry points must be same for static methods and vice versa"); | |
944 } | |
945 | |
946 bool printnmethods = PrintNMethods | |
947 || CompilerOracle::should_print(_method) | |
948 || CompilerOracle::has_option_string(_method, "PrintNMethods"); | |
949 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) { | |
950 print_nmethod(printnmethods); | |
951 } | |
952 } | |
953 | |
954 | |
955 // Print a short set of xml attributes to identify this nmethod. The | |
956 // output should be embedded in some other element. | |
957 void nmethod::log_identity(xmlStream* log) const { | |
958 log->print(" compile_id='%d'", compile_id()); | |
959 const char* nm_kind = compile_kind(); | |
960 if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind); | |
961 if (compiler() != NULL) { | |
962 log->print(" compiler='%s'", compiler()->name()); | |
963 } | |
964 if (TieredCompilation) { | |
965 log->print(" level='%d'", comp_level()); | |
966 } | |
967 } | |
968 | |
969 | |
970 #define LOG_OFFSET(log, name) \ | |
971 if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \ | |
972 log->print(" " XSTR(name) "_offset='%d'" , \ | |
973 (intptr_t)name##_begin() - (intptr_t)this) | |
974 | |
975 | |
976 void nmethod::log_new_nmethod() const { | |
977 if (LogCompilation && xtty != NULL) { | |
978 ttyLocker ttyl; | |
979 HandleMark hm; | |
980 xtty->begin_elem("nmethod"); | |
981 log_identity(xtty); | |
982 xtty->print(" entry='" INTPTR_FORMAT "' size='%d'", code_begin(), size()); | |
983 xtty->print(" address='" INTPTR_FORMAT "'", (intptr_t) this); | |
984 | |
985 LOG_OFFSET(xtty, relocation); | |
986 LOG_OFFSET(xtty, consts); | |
987 LOG_OFFSET(xtty, insts); | |
988 LOG_OFFSET(xtty, stub); | |
989 LOG_OFFSET(xtty, scopes_data); | |
990 LOG_OFFSET(xtty, scopes_pcs); | |
991 LOG_OFFSET(xtty, dependencies); | |
992 LOG_OFFSET(xtty, handler_table); | |
993 LOG_OFFSET(xtty, nul_chk_table); | |
994 LOG_OFFSET(xtty, oops); | |
995 | |
996 xtty->method(method()); | |
997 xtty->stamp(); | |
998 xtty->end_elem(); | |
999 } | |
1000 } | |
1001 | |
1002 #undef LOG_OFFSET | |
1003 | |
1004 | |
1005 // Print out more verbose output usually for a newly created nmethod. | |
1006 void nmethod::print_on(outputStream* st, const char* msg) const { | |
1007 if (st != NULL) { | |
1008 ttyLocker ttyl; | |
1009 if (WizardMode) { | |
1010 CompileTask::print_compilation(st, this, msg, /*short_form:*/ true); | |
1011 st->print_cr(" (" INTPTR_FORMAT ")", this); | |
1012 } else { | |
1013 CompileTask::print_compilation(st, this, msg, /*short_form:*/ false); | |
1014 } | |
1015 } | |
1016 } | |
1017 | |
1018 | |
1019 void nmethod::print_nmethod(bool printmethod) { | |
1020 ttyLocker ttyl; // keep the following output all in one block | |
1021 if (xtty != NULL) { | |
1022 xtty->begin_head("print_nmethod"); | |
1023 xtty->stamp(); | |
1024 xtty->end_head(); | |
1025 } | |
1026 // print the header part first | |
1027 print(); | |
1028 // then print the requested information | |
1029 if (printmethod) { | |
1030 print_code(); | |
1031 print_pcs(); | |
1032 if (oop_maps()) { | |
1033 oop_maps()->print(); | |
1034 } | |
1035 } | |
1036 if (PrintDebugInfo) { | |
1037 print_scopes(); | |
1038 } | |
1039 if (PrintRelocations) { | |
1040 print_relocations(); | |
1041 } | |
1042 if (PrintDependencies) { | |
1043 print_dependencies(); | |
1044 } | |
1045 if (PrintExceptionHandlers) { | |
1046 print_handler_table(); | |
1047 print_nul_chk_table(); | |
1048 } | |
1049 if (xtty != NULL) { | |
1050 xtty->tail("print_nmethod"); | |
1051 } | |
1052 } | |
1053 | |
1054 | |
1055 // Promote one word from an assembly-time handle to a live embedded oop. | |
1056 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) { | |
1057 if (handle == NULL || | |
1058 // As a special case, IC oops are initialized to 1 or -1. | |
1059 handle == (jobject) Universe::non_oop_word()) { | |
1060 (*dest) = (oop) handle; | |
1061 } else { | |
1062 (*dest) = JNIHandles::resolve_non_null(handle); | |
1063 } | |
1064 } | |
1065 | |
1066 | |
1067 // Have to have the same name because it's called by a template | |
1068 void nmethod::copy_values(GrowableArray<jobject>* array) { | |
1069 int length = array->length(); | |
1070 assert((address)(oops_begin() + length) <= (address)oops_end(), "oops big enough"); | |
1071 oop* dest = oops_begin(); | |
1072 for (int index = 0 ; index < length; index++) { | |
1073 initialize_immediate_oop(&dest[index], array->at(index)); | |
1074 } | |
1075 | |
1076 // Now we can fix up all the oops in the code. We need to do this | |
1077 // in the code because the assembler uses jobjects as placeholders. | |
1078 // The code and relocations have already been initialized by the | |
1079 // CodeBlob constructor, so it is valid even at this early point to | |
1080 // iterate over relocations and patch the code. | |
1081 fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true); | |
1082 } | |
1083 | |
1084 void nmethod::copy_values(GrowableArray<Metadata*>* array) { | |
1085 int length = array->length(); | |
1086 assert((address)(metadata_begin() + length) <= (address)metadata_end(), "big enough"); | |
1087 Metadata** dest = metadata_begin(); | |
1088 for (int index = 0 ; index < length; index++) { | |
1089 dest[index] = array->at(index); | |
1090 } | |
1091 } | |
1092 | |
1093 bool nmethod::is_at_poll_return(address pc) { | |
1094 RelocIterator iter(this, pc, pc+1); | |
1095 while (iter.next()) { | |
1096 if (iter.type() == relocInfo::poll_return_type) | |
1097 return true; | |
1098 } | |
1099 return false; | |
1100 } | |
1101 | |
1102 | |
1103 bool nmethod::is_at_poll_or_poll_return(address pc) { | |
1104 RelocIterator iter(this, pc, pc+1); | |
1105 while (iter.next()) { | |
1106 relocInfo::relocType t = iter.type(); | |
1107 if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) | |
1108 return true; | |
1109 } | |
1110 return false; | |
1111 } | |
1112 | |
1113 | |
1114 void nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) { | |
1115 // re-patch all oop-bearing instructions, just in case some oops moved | |
1116 RelocIterator iter(this, begin, end); | |
1117 while (iter.next()) { | |
1118 if (iter.type() == relocInfo::oop_type) { | |
1119 oop_Relocation* reloc = iter.oop_reloc(); | |
1120 if (initialize_immediates && reloc->oop_is_immediate()) { | |
1121 oop* dest = reloc->oop_addr(); | |
1122 initialize_immediate_oop(dest, (jobject) *dest); | |
1123 } | |
1124 // Refresh the oop-related bits of this instruction. | |
1125 reloc->fix_oop_relocation(); | |
1126 } else if (iter.type() == relocInfo::metadata_type) { | |
1127 metadata_Relocation* reloc = iter.metadata_reloc(); | |
1128 reloc->fix_metadata_relocation(); | |
1129 } | |
1130 | |
1131 // There must not be any interfering patches or breakpoints. | |
1132 assert(!(iter.type() == relocInfo::breakpoint_type | |
1133 && iter.breakpoint_reloc()->active()), | |
1134 "no active breakpoint"); | |
1135 } | |
1136 } | |
1137 | |
1138 | |
1139 void nmethod::verify_oop_relocations() { | |
1140 // Ensure sure that the code matches the current oop values | |
1141 RelocIterator iter(this, NULL, NULL); | |
1142 while (iter.next()) { | |
1143 if (iter.type() == relocInfo::oop_type) { | |
1144 oop_Relocation* reloc = iter.oop_reloc(); | |
1145 if (!reloc->oop_is_immediate()) { | |
1146 reloc->verify_oop_relocation(); | |
1147 } | |
1148 } | |
1149 } | |
1150 } | |
1151 | |
1152 | |
1153 ScopeDesc* nmethod::scope_desc_at(address pc) { | |
1154 PcDesc* pd = pc_desc_at(pc); | |
1155 guarantee(pd != NULL, "scope must be present"); | |
1156 return new ScopeDesc(this, pd->scope_decode_offset(), | |
1157 pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), | |
1158 pd->return_oop()); | |
1159 } | |
1160 | |
1161 | |
1162 void nmethod::clear_inline_caches() { | |
1163 assert(SafepointSynchronize::is_at_safepoint(), "cleaning of IC's only allowed at safepoint"); | |
1164 if (is_zombie()) { | |
1165 return; | |
1166 } | |
1167 | |
1168 RelocIterator iter(this); | |
1169 while (iter.next()) { | |
1170 iter.reloc()->clear_inline_cache(); | |
1171 } | |
1172 } | |
1173 | |
1174 | |
1175 void nmethod::cleanup_inline_caches() { | |
1176 | |
1177 assert_locked_or_safepoint(CompiledIC_lock); | |
1178 | |
1179 // If the method is not entrant or zombie then a JMP is plastered over the | |
1180 // first few bytes. If an oop in the old code was there, that oop | |
1181 // should not get GC'd. Skip the first few bytes of oops on | |
1182 // not-entrant methods. | |
1183 address low_boundary = verified_entry_point(); | |
1184 if (!is_in_use()) { | |
1185 low_boundary += NativeJump::instruction_size; | |
1186 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1187 // This means that the low_boundary is going to be a little too high. | |
1188 // This shouldn't matter, since oops of non-entrant methods are never used. | |
1189 // In fact, why are we bothering to look at oops in a non-entrant method?? | |
1190 } | |
1191 | |
1192 // Find all calls in an nmethod, and clear the ones that points to zombie methods | |
1193 ResourceMark rm; | |
1194 RelocIterator iter(this, low_boundary); | |
1195 while(iter.next()) { | |
1196 switch(iter.type()) { | |
1197 case relocInfo::virtual_call_type: | |
1198 case relocInfo::opt_virtual_call_type: { | |
1199 CompiledIC *ic = CompiledIC_at(iter.reloc()); | |
1200 // Ok, to lookup references to zombies here | |
1201 CodeBlob *cb = CodeCache::find_blob_unsafe(ic->ic_destination()); | |
1202 if( cb != NULL && cb->is_nmethod() ) { | |
1203 nmethod* nm = (nmethod*)cb; | |
1204 // Clean inline caches pointing to both zombie and not_entrant methods | |
1205 if (!nm->is_in_use() || (nm->method()->code() != nm)) ic->set_to_clean(); | |
1206 } | |
1207 break; | |
1208 } | |
1209 case relocInfo::static_call_type: { | |
1210 CompiledStaticCall *csc = compiledStaticCall_at(iter.reloc()); | |
1211 CodeBlob *cb = CodeCache::find_blob_unsafe(csc->destination()); | |
1212 if( cb != NULL && cb->is_nmethod() ) { | |
1213 nmethod* nm = (nmethod*)cb; | |
1214 // Clean inline caches pointing to both zombie and not_entrant methods | |
1215 if (!nm->is_in_use() || (nm->method()->code() != nm)) csc->set_to_clean(); | |
1216 } | |
1217 break; | |
1218 } | |
1219 } | |
1220 } | |
1221 } | |
1222 | |
1223 // This is a private interface with the sweeper. | |
1224 void nmethod::mark_as_seen_on_stack() { | |
1225 assert(is_not_entrant(), "must be a non-entrant method"); | |
1226 // Set the traversal mark to ensure that the sweeper does 2 | |
1227 // cleaning passes before moving to zombie. | |
1228 set_stack_traversal_mark(NMethodSweeper::traversal_count()); | |
1229 } | |
1230 | |
1231 // Tell if a non-entrant method can be converted to a zombie (i.e., | |
1232 // there are no activations on the stack, not in use by the VM, | |
1233 // and not in use by the ServiceThread) | |
1234 bool nmethod::can_not_entrant_be_converted() { | |
1235 assert(is_not_entrant(), "must be a non-entrant method"); | |
1236 | |
1237 // Since the nmethod sweeper only does partial sweep the sweeper's traversal | |
1238 // count can be greater than the stack traversal count before it hits the | |
1239 // nmethod for the second time. | |
1240 return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() && | |
1241 !is_locked_by_vm(); | |
1242 } | |
1243 | |
1244 void nmethod::inc_decompile_count() { | |
7154
5d0bb7d52783
changes to support Graal co-existing with the other HotSpot compiler(s) and being used for explicit compilation requests and code installation via the Graal API
Doug Simon <doug.simon@oracle.com>
parents:
7125
diff
changeset
|
1245 if (!is_compiled_by_c2() && !is_compiled_by_graal()) return; |
7066 | 1246 // Could be gated by ProfileTraps, but do not bother... |
1247 Method* m = method(); | |
1248 if (m == NULL) return; | |
1249 MethodData* mdo = m->method_data(); | |
1250 if (mdo == NULL) return; | |
1251 // There is a benign race here. See comments in methodData.hpp. | |
1252 mdo->inc_decompile_count(); | |
1253 } | |
1254 | |
1255 void nmethod::make_unloaded(BoolObjectClosure* is_alive, oop cause) { | |
1256 | |
1257 post_compiled_method_unload(); | |
1258 | |
1259 // Since this nmethod is being unloaded, make sure that dependencies | |
1260 // recorded in instanceKlasses get flushed and pass non-NULL closure to | |
1261 // indicate that this work is being done during a GC. | |
1262 assert(Universe::heap()->is_gc_active(), "should only be called during gc"); | |
1263 assert(is_alive != NULL, "Should be non-NULL"); | |
1264 // A non-NULL is_alive closure indicates that this is being called during GC. | |
1265 flush_dependencies(is_alive); | |
1266 | |
1267 // Break cycle between nmethod & method | |
1268 if (TraceClassUnloading && WizardMode) { | |
1269 tty->print_cr("[Class unloading: Making nmethod " INTPTR_FORMAT | |
1270 " unloadable], Method*(" INTPTR_FORMAT | |
1271 "), cause(" INTPTR_FORMAT ")", | |
1272 this, (address)_method, (address)cause); | |
1273 if (!Universe::heap()->is_gc_active()) | |
1274 cause->klass()->print(); | |
1275 } | |
1276 // Unlink the osr method, so we do not look this up again | |
1277 if (is_osr_method()) { | |
1278 invalidate_osr_method(); | |
1279 } | |
1280 // If _method is already NULL the Method* is about to be unloaded, | |
1281 // so we don't have to break the cycle. Note that it is possible to | |
1282 // have the Method* live here, in case we unload the nmethod because | |
1283 // it is pointing to some oop (other than the Method*) being unloaded. | |
1284 if (_method != NULL) { | |
1285 // OSR methods point to the Method*, but the Method* does not | |
1286 // point back! | |
1287 if (_method->code() == this) { | |
1288 _method->clear_code(); // Break a cycle | |
1289 } | |
1290 _method = NULL; // Clear the method of this dead nmethod | |
1291 } | |
1292 | |
1293 #ifdef GRAAL | |
1294 if (_graal_installed_code != NULL) { | |
1295 HotSpotInstalledCode::set_nmethod(_graal_installed_code, 0); | |
1296 _graal_installed_code = NULL; | |
1297 } | |
1298 #endif | |
1299 | |
1300 // Make the class unloaded - i.e., change state and notify sweeper | |
1301 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
1302 if (is_in_use()) { | |
1303 // Transitioning directly from live to unloaded -- so | |
1304 // we need to force a cache clean-up; remember this | |
1305 // for later on. | |
1306 CodeCache::set_needs_cache_clean(true); | |
1307 } | |
1308 _state = unloaded; | |
1309 | |
1310 // Log the unloading. | |
1311 log_state_change(); | |
1312 | |
1313 // The Method* is gone at this point | |
1314 assert(_method == NULL, "Tautology"); | |
1315 | |
1316 set_osr_link(NULL); | |
1317 //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods | |
1318 NMethodSweeper::notify(this); | |
1319 } | |
1320 | |
1321 void nmethod::invalidate_osr_method() { | |
1322 assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); | |
1323 // Remove from list of active nmethods | |
1324 if (method() != NULL) | |
1325 method()->method_holder()->remove_osr_nmethod(this); | |
1326 // Set entry as invalid | |
1327 _entry_bci = InvalidOSREntryBci; | |
1328 } | |
1329 | |
1330 void nmethod::log_state_change() const { | |
1331 if (LogCompilation) { | |
1332 if (xtty != NULL) { | |
1333 ttyLocker ttyl; // keep the following output all in one block | |
1334 if (_state == unloaded) { | |
1335 xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'", | |
1336 os::current_thread_id()); | |
1337 } else { | |
1338 xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s", | |
1339 os::current_thread_id(), | |
1340 (_state == zombie ? " zombie='1'" : "")); | |
1341 } | |
1342 log_identity(xtty); | |
1343 xtty->stamp(); | |
1344 xtty->end_elem(); | |
1345 } | |
1346 } | |
1347 if (PrintCompilation && _state != unloaded) { | |
1348 print_on(tty, _state == zombie ? "made zombie" : "made not entrant"); | |
1349 } | |
1350 } | |
1351 | |
1352 // Common functionality for both make_not_entrant and make_zombie | |
1353 bool nmethod::make_not_entrant_or_zombie(unsigned int state) { | |
1354 assert(state == zombie || state == not_entrant, "must be zombie or not_entrant"); | |
1355 assert(!is_zombie(), "should not already be a zombie"); | |
1356 | |
1357 // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below. | |
1358 nmethodLocker nml(this); | |
1359 methodHandle the_method(method()); | |
1360 No_Safepoint_Verifier nsv; | |
1361 | |
1362 { | |
1363 // invalidate osr nmethod before acquiring the patching lock since | |
1364 // they both acquire leaf locks and we don't want a deadlock. | |
1365 // This logic is equivalent to the logic below for patching the | |
1366 // verified entry point of regular methods. | |
1367 if (is_osr_method()) { | |
1368 // this effectively makes the osr nmethod not entrant | |
1369 invalidate_osr_method(); | |
1370 } | |
1371 | |
1372 // Enter critical section. Does not block for safepoint. | |
1373 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); | |
1374 | |
1375 if (_state == state) { | |
1376 // another thread already performed this transition so nothing | |
1377 // to do, but return false to indicate this. | |
1378 return false; | |
1379 } | |
1380 | |
1381 #ifdef GRAAL | |
1382 if (_graal_installed_code != NULL) { | |
1383 HotSpotInstalledCode::set_nmethod(_graal_installed_code, 0); | |
1384 _graal_installed_code = NULL; | |
1385 } | |
1386 #endif | |
1387 | |
1388 // The caller can be calling the method statically or through an inline | |
1389 // cache call. | |
1390 if (!is_osr_method() && !is_not_entrant()) { | |
1391 NativeJump::patch_verified_entry(entry_point(), verified_entry_point(), | |
1392 SharedRuntime::get_handle_wrong_method_stub()); | |
1393 } | |
1394 | |
1395 if (is_in_use()) { | |
1396 // It's a true state change, so mark the method as decompiled. | |
1397 // Do it only for transition from alive. | |
1398 inc_decompile_count(); | |
1399 } | |
1400 | |
1401 // Change state | |
1402 _state = state; | |
1403 | |
1404 // Log the transition once | |
1405 log_state_change(); | |
1406 | |
1407 // Remove nmethod from method. | |
1408 // We need to check if both the _code and _from_compiled_code_entry_point | |
1409 // refer to this nmethod because there is a race in setting these two fields | |
1410 // in Method* as seen in bugid 4947125. | |
1411 // If the vep() points to the zombie nmethod, the memory for the nmethod | |
1412 // could be flushed and the compiler and vtable stubs could still call | |
1413 // through it. | |
1414 if (method() != NULL && (method()->code() == this || | |
1415 method()->from_compiled_entry() == verified_entry_point())) { | |
1416 HandleMark hm; | |
1417 method()->clear_code(); | |
1418 } | |
1419 | |
1420 if (state == not_entrant) { | |
1421 mark_as_seen_on_stack(); | |
1422 } | |
1423 | |
1424 } // leave critical region under Patching_lock | |
1425 | |
1426 // When the nmethod becomes zombie it is no longer alive so the | |
1427 // dependencies must be flushed. nmethods in the not_entrant | |
1428 // state will be flushed later when the transition to zombie | |
1429 // happens or they get unloaded. | |
1430 if (state == zombie) { | |
1431 { | |
1432 // Flushing dependecies must be done before any possible | |
1433 // safepoint can sneak in, otherwise the oops used by the | |
1434 // dependency logic could have become stale. | |
1435 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
1436 flush_dependencies(NULL); | |
1437 } | |
1438 | |
1439 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload | |
1440 // event and it hasn't already been reported for this nmethod then | |
1441 // report it now. The event may have been reported earilier if the GC | |
1442 // marked it for unloading). JvmtiDeferredEventQueue support means | |
1443 // we no longer go to a safepoint here. | |
1444 post_compiled_method_unload(); | |
1445 | |
1446 #ifdef ASSERT | |
1447 // It's no longer safe to access the oops section since zombie | |
1448 // nmethods aren't scanned for GC. | |
1449 _oops_are_stale = true; | |
1450 #endif | |
1451 } else { | |
1452 assert(state == not_entrant, "other cases may need to be handled differently"); | |
1453 } | |
1454 | |
1455 if (TraceCreateZombies) { | |
7112
60bef2672469
changed System.err output to TTY to avoid that DaCapo benchmarks fail digest validation
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7088
diff
changeset
|
1456 ResourceMark m; |
60bef2672469
changed System.err output to TTY to avoid that DaCapo benchmarks fail digest validation
Christian Haeubl <haeubl@ssw.jku.at>
parents:
7088
diff
changeset
|
1457 tty->print_cr("nmethod <" INTPTR_FORMAT "> %s code made %s", this, this->method()->name_and_sig_as_C_string(), (state == not_entrant) ? "not entrant" : "zombie"); |
7066 | 1458 } |
1459 | |
1460 // Make sweeper aware that there is a zombie method that needs to be removed | |
1461 NMethodSweeper::notify(this); | |
1462 | |
1463 return true; | |
1464 } | |
1465 | |
1466 void nmethod::flush() { | |
1467 // Note that there are no valid oops in the nmethod anymore. | |
1468 assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method"); | |
1469 assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation"); | |
1470 | |
1471 assert (!is_locked_by_vm(), "locked methods shouldn't be flushed"); | |
1472 assert_locked_or_safepoint(CodeCache_lock); | |
1473 | |
1474 // completely deallocate this method | |
1475 Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, this); | |
1476 if (PrintMethodFlushing) { | |
1477 tty->print_cr("*flushing nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT "/Free CodeCache:" SIZE_FORMAT "Kb", | |
1478 _compile_id, this, CodeCache::nof_blobs(), CodeCache::unallocated_capacity()/1024); | |
1479 } | |
1480 | |
1481 // We need to deallocate any ExceptionCache data. | |
1482 // Note that we do not need to grab the nmethod lock for this, it | |
1483 // better be thread safe if we're disposing of it! | |
1484 ExceptionCache* ec = exception_cache(); | |
1485 set_exception_cache(NULL); | |
1486 while(ec != NULL) { | |
1487 ExceptionCache* next = ec->next(); | |
1488 delete ec; | |
1489 ec = next; | |
1490 } | |
1491 | |
1492 if (on_scavenge_root_list()) { | |
1493 CodeCache::drop_scavenge_root_nmethod(this); | |
1494 } | |
1495 | |
1496 if (is_speculatively_disconnected()) { | |
1497 CodeCache::remove_saved_code(this); | |
1498 } | |
1499 | |
1500 #ifdef SHARK | |
1501 ((SharkCompiler *) compiler())->free_compiled_method(insts_begin()); | |
1502 #endif // SHARK | |
1503 | |
1504 ((CodeBlob*)(this))->flush(); | |
1505 | |
1506 CodeCache::free(this); | |
1507 } | |
1508 | |
1509 | |
1510 // | |
1511 // Notify all classes this nmethod is dependent on that it is no | |
1512 // longer dependent. This should only be called in two situations. | |
1513 // First, when a nmethod transitions to a zombie all dependents need | |
1514 // to be clear. Since zombification happens at a safepoint there's no | |
1515 // synchronization issues. The second place is a little more tricky. | |
1516 // During phase 1 of mark sweep class unloading may happen and as a | |
1517 // result some nmethods may get unloaded. In this case the flushing | |
1518 // of dependencies must happen during phase 1 since after GC any | |
1519 // dependencies in the unloaded nmethod won't be updated, so | |
1520 // traversing the dependency information in unsafe. In that case this | |
1521 // function is called with a non-NULL argument and this function only | |
1522 // notifies instanceKlasses that are reachable | |
1523 | |
1524 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) { | |
1525 assert_locked_or_safepoint(CodeCache_lock); | |
1526 assert(Universe::heap()->is_gc_active() == (is_alive != NULL), | |
1527 "is_alive is non-NULL if and only if we are called during GC"); | |
1528 if (!has_flushed_dependencies()) { | |
1529 set_has_flushed_dependencies(); | |
1530 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
1531 Klass* klass = deps.context_type(); | |
1532 if (klass == NULL) continue; // ignore things like evol_method | |
1533 | |
1534 // During GC the is_alive closure is non-NULL, and is used to | |
1535 // determine liveness of dependees that need to be updated. | |
1536 if (is_alive == NULL || klass->is_loader_alive(is_alive)) { | |
1537 InstanceKlass::cast(klass)->remove_dependent_nmethod(this); | |
1538 } | |
1539 } | |
1540 } | |
1541 } | |
1542 | |
1543 | |
1544 // If this oop is not live, the nmethod can be unloaded. | |
1545 bool nmethod::can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred) { | |
1546 assert(root != NULL, "just checking"); | |
1547 oop obj = *root; | |
1548 if (obj == NULL || is_alive->do_object_b(obj)) { | |
1549 return false; | |
1550 } | |
1551 | |
1552 // If ScavengeRootsInCode is true, an nmethod might be unloaded | |
1553 // simply because one of its constant oops has gone dead. | |
1554 // No actual classes need to be unloaded in order for this to occur. | |
1555 assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading"); | |
1556 make_unloaded(is_alive, obj); | |
1557 return true; | |
1558 } | |
1559 | |
1560 // ------------------------------------------------------------------ | |
1561 // post_compiled_method_load_event | |
1562 // new method for install_code() path | |
1563 // Transfer information from compilation to jvmti | |
1564 void nmethod::post_compiled_method_load_event() { | |
1565 | |
1566 Method* moop = method(); | |
1567 #ifndef USDT2 | |
1568 HS_DTRACE_PROBE8(hotspot, compiled__method__load, | |
1569 moop->klass_name()->bytes(), | |
1570 moop->klass_name()->utf8_length(), | |
1571 moop->name()->bytes(), | |
1572 moop->name()->utf8_length(), | |
1573 moop->signature()->bytes(), | |
1574 moop->signature()->utf8_length(), | |
1575 insts_begin(), insts_size()); | |
1576 #else /* USDT2 */ | |
1577 HOTSPOT_COMPILED_METHOD_LOAD( | |
1578 (char *) moop->klass_name()->bytes(), | |
1579 moop->klass_name()->utf8_length(), | |
1580 (char *) moop->name()->bytes(), | |
1581 moop->name()->utf8_length(), | |
1582 (char *) moop->signature()->bytes(), | |
1583 moop->signature()->utf8_length(), | |
1584 insts_begin(), insts_size()); | |
1585 #endif /* USDT2 */ | |
1586 | |
1587 if (JvmtiExport::should_post_compiled_method_load() || | |
1588 JvmtiExport::should_post_compiled_method_unload()) { | |
1589 get_and_cache_jmethod_id(); | |
1590 } | |
1591 | |
1592 if (JvmtiExport::should_post_compiled_method_load()) { | |
1593 // Let the Service thread (which is a real Java thread) post the event | |
1594 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); | |
1595 JvmtiDeferredEventQueue::enqueue( | |
1596 JvmtiDeferredEvent::compiled_method_load_event(this)); | |
1597 } | |
1598 } | |
1599 | |
1600 jmethodID nmethod::get_and_cache_jmethod_id() { | |
1601 if (_jmethod_id == NULL) { | |
1602 // Cache the jmethod_id since it can no longer be looked up once the | |
1603 // method itself has been marked for unloading. | |
1604 _jmethod_id = method()->jmethod_id(); | |
1605 } | |
1606 return _jmethod_id; | |
1607 } | |
1608 | |
1609 void nmethod::post_compiled_method_unload() { | |
1610 if (unload_reported()) { | |
1611 // During unloading we transition to unloaded and then to zombie | |
1612 // and the unloading is reported during the first transition. | |
1613 return; | |
1614 } | |
1615 | |
1616 assert(_method != NULL && !is_unloaded(), "just checking"); | |
1617 DTRACE_METHOD_UNLOAD_PROBE(method()); | |
1618 | |
1619 // If a JVMTI agent has enabled the CompiledMethodUnload event then | |
1620 // post the event. Sometime later this nmethod will be made a zombie | |
1621 // by the sweeper but the Method* will not be valid at that point. | |
1622 // If the _jmethod_id is null then no load event was ever requested | |
1623 // so don't bother posting the unload. The main reason for this is | |
1624 // that the jmethodID is a weak reference to the Method* so if | |
1625 // it's being unloaded there's no way to look it up since the weak | |
1626 // ref will have been cleared. | |
1627 if (_jmethod_id != NULL && JvmtiExport::should_post_compiled_method_unload()) { | |
1628 assert(!unload_reported(), "already unloaded"); | |
1629 JvmtiDeferredEvent event = | |
1630 JvmtiDeferredEvent::compiled_method_unload_event(this, | |
1631 _jmethod_id, insts_begin()); | |
1632 if (SafepointSynchronize::is_at_safepoint()) { | |
1633 // Don't want to take the queueing lock. Add it as pending and | |
1634 // it will get enqueued later. | |
1635 JvmtiDeferredEventQueue::add_pending_event(event); | |
1636 } else { | |
1637 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); | |
1638 JvmtiDeferredEventQueue::enqueue(event); | |
1639 } | |
1640 } | |
1641 | |
1642 // The JVMTI CompiledMethodUnload event can be enabled or disabled at | |
1643 // any time. As the nmethod is being unloaded now we mark it has | |
1644 // having the unload event reported - this will ensure that we don't | |
1645 // attempt to report the event in the unlikely scenario where the | |
1646 // event is enabled at the time the nmethod is made a zombie. | |
1647 set_unload_reported(); | |
1648 } | |
1649 | |
1650 // This is called at the end of the strong tracing/marking phase of a | |
1651 // GC to unload an nmethod if it contains otherwise unreachable | |
1652 // oops. | |
1653 | |
1654 void nmethod::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) { | |
1655 // Make sure the oop's ready to receive visitors | |
1656 assert(!is_zombie() && !is_unloaded(), | |
1657 "should not call follow on zombie or unloaded nmethod"); | |
1658 | |
1659 // If the method is not entrant then a JMP is plastered over the | |
1660 // first few bytes. If an oop in the old code was there, that oop | |
1661 // should not get GC'd. Skip the first few bytes of oops on | |
1662 // not-entrant methods. | |
1663 address low_boundary = verified_entry_point(); | |
1664 if (is_not_entrant()) { | |
1665 low_boundary += NativeJump::instruction_size; | |
1666 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1667 // (See comment above.) | |
1668 } | |
1669 | |
1670 // The RedefineClasses() API can cause the class unloading invariant | |
1671 // to no longer be true. See jvmtiExport.hpp for details. | |
1672 // Also, leave a debugging breadcrumb in local flag. | |
1673 bool a_class_was_redefined = JvmtiExport::has_redefined_a_class(); | |
1674 if (a_class_was_redefined) { | |
1675 // This set of the unloading_occurred flag is done before the | |
1676 // call to post_compiled_method_unload() so that the unloading | |
1677 // of this nmethod is reported. | |
1678 unloading_occurred = true; | |
1679 } | |
1680 | |
1681 #ifdef GRAAL | |
1682 // Follow Graal method | |
1683 if (_graal_installed_code != NULL && can_unload(is_alive, (oop*)&_graal_installed_code, unloading_occurred)) { | |
1684 return; | |
1685 } | |
1686 #endif | |
1687 | |
1688 // Exception cache | |
1689 ExceptionCache* ec = exception_cache(); | |
1690 while (ec != NULL) { | |
1691 Klass* ex_klass = ec->exception_type(); | |
1692 ExceptionCache* next_ec = ec->next(); | |
1693 if (ex_klass != NULL && !ex_klass->is_loader_alive(is_alive)) { | |
1694 remove_from_exception_cache(ec); | |
1695 } | |
1696 ec = next_ec; | |
1697 } | |
1698 | |
1699 // If class unloading occurred we first iterate over all inline caches and | |
1700 // clear ICs where the cached oop is referring to an unloaded klass or method. | |
1701 // The remaining live cached oops will be traversed in the relocInfo::oop_type | |
1702 // iteration below. | |
1703 if (unloading_occurred) { | |
1704 RelocIterator iter(this, low_boundary); | |
1705 while(iter.next()) { | |
1706 if (iter.type() == relocInfo::virtual_call_type) { | |
1707 CompiledIC *ic = CompiledIC_at(iter.reloc()); | |
1708 if (ic->is_icholder_call()) { | |
1709 // The only exception is compiledICHolder oops which may | |
1710 // yet be marked below. (We check this further below). | |
1711 CompiledICHolder* cichk_oop = ic->cached_icholder(); | |
1712 if (cichk_oop->holder_method()->method_holder()->is_loader_alive(is_alive) && | |
1713 cichk_oop->holder_klass()->is_loader_alive(is_alive)) { | |
1714 continue; | |
1715 } | |
1716 } else { | |
1717 Metadata* ic_oop = ic->cached_metadata(); | |
1718 if (ic_oop != NULL) { | |
1719 if (ic_oop->is_klass()) { | |
1720 if (((Klass*)ic_oop)->is_loader_alive(is_alive)) { | |
1721 continue; | |
1722 } | |
1723 } else if (ic_oop->is_method()) { | |
1724 if (((Method*)ic_oop)->method_holder()->is_loader_alive(is_alive)) { | |
1725 continue; | |
1726 } | |
1727 } else { | |
1728 ShouldNotReachHere(); | |
1729 } | |
1730 } | |
1731 } | |
1732 ic->set_to_clean(); | |
1733 } | |
1734 } | |
1735 } | |
1736 | |
1737 // Compiled code | |
1738 { | |
1739 RelocIterator iter(this, low_boundary); | |
1740 while (iter.next()) { | |
1741 if (iter.type() == relocInfo::oop_type) { | |
1742 oop_Relocation* r = iter.oop_reloc(); | |
1743 // In this loop, we must only traverse those oops directly embedded in | |
1744 // the code. Other oops (oop_index>0) are seen as part of scopes_oops. | |
1745 assert(1 == (r->oop_is_immediate()) + | |
1746 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), | |
1747 "oop must be found in exactly one place"); | |
1748 if (r->oop_is_immediate() && r->oop_value() != NULL) { | |
1749 if (can_unload(is_alive, r->oop_addr(), unloading_occurred)) { | |
1750 return; | |
1751 } | |
1752 } | |
1753 } | |
1754 } | |
1755 } | |
1756 | |
1757 | |
1758 // Scopes | |
1759 for (oop* p = oops_begin(); p < oops_end(); p++) { | |
1760 if (*p == Universe::non_oop_word()) continue; // skip non-oops | |
1761 if (can_unload(is_alive, p, unloading_occurred)) { | |
1762 return; | |
1763 } | |
1764 } | |
1765 | |
1766 // Ensure that all metadata is still alive | |
1767 verify_metadata_loaders(low_boundary, is_alive); | |
1768 } | |
1769 | |
1770 #ifdef ASSERT | |
1771 | |
1772 class CheckClass : AllStatic { | |
1773 static BoolObjectClosure* _is_alive; | |
1774 | |
1775 // Check class_loader is alive for this bit of metadata. | |
1776 static void check_class(Metadata* md) { | |
1777 Klass* klass = NULL; | |
1778 if (md->is_klass()) { | |
1779 klass = ((Klass*)md); | |
1780 } else if (md->is_method()) { | |
1781 klass = ((Method*)md)->method_holder(); | |
1782 } else if (md->is_methodData()) { | |
1783 klass = ((MethodData*)md)->method()->method_holder(); | |
1784 } else { | |
1785 md->print(); | |
1786 ShouldNotReachHere(); | |
1787 } | |
1788 assert(klass->is_loader_alive(_is_alive), "must be alive"); | |
1789 } | |
1790 public: | |
1791 static void do_check_class(BoolObjectClosure* is_alive, nmethod* nm) { | |
1792 assert(SafepointSynchronize::is_at_safepoint(), "this is only ok at safepoint"); | |
1793 _is_alive = is_alive; | |
1794 nm->metadata_do(check_class); | |
1795 } | |
1796 }; | |
1797 | |
1798 // This is called during a safepoint so can use static data | |
1799 BoolObjectClosure* CheckClass::_is_alive = NULL; | |
1800 #endif // ASSERT | |
1801 | |
1802 | |
1803 // Processing of oop references should have been sufficient to keep | |
1804 // all strong references alive. Any weak references should have been | |
1805 // cleared as well. Visit all the metadata and ensure that it's | |
1806 // really alive. | |
1807 void nmethod::verify_metadata_loaders(address low_boundary, BoolObjectClosure* is_alive) { | |
1808 #ifdef ASSERT | |
1809 RelocIterator iter(this, low_boundary); | |
1810 while (iter.next()) { | |
1811 // static_stub_Relocations may have dangling references to | |
1812 // Method*s so trim them out here. Otherwise it looks like | |
1813 // compiled code is maintaining a link to dead metadata. | |
1814 address static_call_addr = NULL; | |
1815 if (iter.type() == relocInfo::opt_virtual_call_type) { | |
1816 CompiledIC* cic = CompiledIC_at(iter.reloc()); | |
1817 if (!cic->is_call_to_interpreted()) { | |
1818 static_call_addr = iter.addr(); | |
1819 cic->set_to_clean(); | |
1820 } | |
1821 } else if (iter.type() == relocInfo::static_call_type) { | |
1822 CompiledStaticCall* csc = compiledStaticCall_at(iter.reloc()); | |
1823 if (!csc->is_call_to_interpreted()) { | |
1824 static_call_addr = iter.addr(); | |
1825 csc->set_to_clean(); | |
1826 } | |
1827 } | |
1828 if (static_call_addr != NULL) { | |
1829 RelocIterator sciter(this, low_boundary); | |
1830 while (sciter.next()) { | |
1831 if (sciter.type() == relocInfo::static_stub_type && | |
1832 sciter.static_stub_reloc()->static_call() == static_call_addr) { | |
1833 sciter.static_stub_reloc()->clear_inline_cache(); | |
1834 } | |
1835 } | |
1836 } | |
1837 } | |
1838 // Check that the metadata embedded in the nmethod is alive | |
1839 CheckClass::do_check_class(is_alive, this); | |
1840 #endif | |
1841 } | |
1842 | |
1843 | |
1844 // Iterate over metadata calling this function. Used by RedefineClasses | |
1845 void nmethod::metadata_do(void f(Metadata*)) { | |
1846 address low_boundary = verified_entry_point(); | |
1847 if (is_not_entrant()) { | |
1848 low_boundary += NativeJump::instruction_size; | |
1849 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1850 // (See comment above.) | |
1851 } | |
1852 { | |
1853 // Visit all immediate references that are embedded in the instruction stream. | |
1854 RelocIterator iter(this, low_boundary); | |
1855 while (iter.next()) { | |
1856 if (iter.type() == relocInfo::metadata_type ) { | |
1857 metadata_Relocation* r = iter.metadata_reloc(); | |
1858 // In this lmetadata, we must only follow those metadatas directly embedded in | |
1859 // the code. Other metadatas (oop_index>0) are seen as part of | |
1860 // the metadata section below. | |
1861 assert(1 == (r->metadata_is_immediate()) + | |
1862 (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()), | |
1863 "metadata must be found in exactly one place"); | |
1864 if (r->metadata_is_immediate() && r->metadata_value() != NULL) { | |
1865 Metadata* md = r->metadata_value(); | |
1866 f(md); | |
1867 } | |
1868 } | |
1869 } | |
1870 } | |
1871 | |
1872 // Visit the metadata section | |
1873 for (Metadata** p = metadata_begin(); p < metadata_end(); p++) { | |
1874 if (*p == Universe::non_oop_word() || *p == NULL) continue; // skip non-oops | |
1875 Metadata* md = *p; | |
1876 f(md); | |
1877 } | |
1878 // Call function Method*, not embedded in these other places. | |
1879 if (_method != NULL) f(_method); | |
1880 } | |
1881 | |
1882 | |
1883 // This method is called twice during GC -- once while | |
1884 // tracing the "active" nmethods on thread stacks during | |
1885 // the (strong) marking phase, and then again when walking | |
1886 // the code cache contents during the weak roots processing | |
1887 // phase. The two uses are distinguished by means of the | |
1888 // 'do_strong_roots_only' flag, which is true in the first | |
1889 // case. We want to walk the weak roots in the nmethod | |
1890 // only in the second case. The weak roots in the nmethod | |
1891 // are the oops in the ExceptionCache and the InlineCache | |
1892 // oops. | |
1893 void nmethod::oops_do(OopClosure* f, bool do_strong_roots_only) { | |
1894 // make sure the oops ready to receive visitors | |
1895 assert(!is_zombie() && !is_unloaded(), | |
1896 "should not call follow on zombie or unloaded nmethod"); | |
1897 | |
1898 // If the method is not entrant or zombie then a JMP is plastered over the | |
1899 // first few bytes. If an oop in the old code was there, that oop | |
1900 // should not get GC'd. Skip the first few bytes of oops on | |
1901 // not-entrant methods. | |
1902 address low_boundary = verified_entry_point(); | |
1903 if (is_not_entrant()) { | |
1904 low_boundary += NativeJump::instruction_size; | |
1905 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. | |
1906 // (See comment above.) | |
1907 } | |
1908 | |
1909 #ifdef GRAAL | |
1910 if (_graal_installed_code != NULL) { | |
1911 f->do_oop((oop*) &_graal_installed_code); | |
1912 } | |
1913 #endif | |
1914 | |
1915 RelocIterator iter(this, low_boundary); | |
1916 | |
1917 while (iter.next()) { | |
1918 if (iter.type() == relocInfo::oop_type ) { | |
1919 oop_Relocation* r = iter.oop_reloc(); | |
1920 // In this loop, we must only follow those oops directly embedded in | |
1921 // the code. Other oops (oop_index>0) are seen as part of scopes_oops. | |
1922 assert(1 == (r->oop_is_immediate()) + | |
1923 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), | |
1924 "oop must be found in exactly one place"); | |
1925 if (r->oop_is_immediate() && r->oop_value() != NULL) { | |
1926 f->do_oop(r->oop_addr()); | |
1927 } | |
1928 } | |
1929 } | |
1930 | |
1931 // Scopes | |
1932 // This includes oop constants not inlined in the code stream. | |
1933 for (oop* p = oops_begin(); p < oops_end(); p++) { | |
1934 if (*p == Universe::non_oop_word()) continue; // skip non-oops | |
1935 f->do_oop(p); | |
1936 } | |
1937 } | |
1938 | |
1939 #define NMETHOD_SENTINEL ((nmethod*)badAddress) | |
1940 | |
1941 nmethod* volatile nmethod::_oops_do_mark_nmethods; | |
1942 | |
1943 // An nmethod is "marked" if its _mark_link is set non-null. | |
1944 // Even if it is the end of the linked list, it will have a non-null link value, | |
1945 // as long as it is on the list. | |
1946 // This code must be MP safe, because it is used from parallel GC passes. | |
1947 bool nmethod::test_set_oops_do_mark() { | |
1948 assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called"); | |
1949 nmethod* observed_mark_link = _oops_do_mark_link; | |
1950 if (observed_mark_link == NULL) { | |
1951 // Claim this nmethod for this thread to mark. | |
1952 observed_mark_link = (nmethod*) | |
1953 Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_link, NULL); | |
1954 if (observed_mark_link == NULL) { | |
1955 | |
1956 // Atomically append this nmethod (now claimed) to the head of the list: | |
1957 nmethod* observed_mark_nmethods = _oops_do_mark_nmethods; | |
1958 for (;;) { | |
1959 nmethod* required_mark_nmethods = observed_mark_nmethods; | |
1960 _oops_do_mark_link = required_mark_nmethods; | |
1961 observed_mark_nmethods = (nmethod*) | |
1962 Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods); | |
1963 if (observed_mark_nmethods == required_mark_nmethods) | |
1964 break; | |
1965 } | |
1966 // Mark was clear when we first saw this guy. | |
1967 NOT_PRODUCT(if (TraceScavenge) print_on(tty, "oops_do, mark")); | |
1968 return false; | |
1969 } | |
1970 } | |
1971 // On fall through, another racing thread marked this nmethod before we did. | |
1972 return true; | |
1973 } | |
1974 | |
1975 void nmethod::oops_do_marking_prologue() { | |
1976 NOT_PRODUCT(if (TraceScavenge) tty->print_cr("[oops_do_marking_prologue")); | |
1977 assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row"); | |
1978 // We use cmpxchg_ptr instead of regular assignment here because the user | |
1979 // may fork a bunch of threads, and we need them all to see the same state. | |
1980 void* observed = Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, NULL); | |
1981 guarantee(observed == NULL, "no races in this sequential code"); | |
1982 } | |
1983 | |
1984 void nmethod::oops_do_marking_epilogue() { | |
1985 assert(_oops_do_mark_nmethods != NULL, "must not call oops_do_marking_epilogue twice in a row"); | |
1986 nmethod* cur = _oops_do_mark_nmethods; | |
1987 while (cur != NMETHOD_SENTINEL) { | |
1988 assert(cur != NULL, "not NULL-terminated"); | |
1989 nmethod* next = cur->_oops_do_mark_link; | |
1990 cur->_oops_do_mark_link = NULL; | |
1991 cur->fix_oop_relocations(); | |
1992 NOT_PRODUCT(if (TraceScavenge) cur->print_on(tty, "oops_do, unmark")); | |
1993 cur = next; | |
1994 } | |
1995 void* required = _oops_do_mark_nmethods; | |
1996 void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required); | |
1997 guarantee(observed == required, "no races in this sequential code"); | |
1998 NOT_PRODUCT(if (TraceScavenge) tty->print_cr("oops_do_marking_epilogue]")); | |
1999 } | |
2000 | |
2001 class DetectScavengeRoot: public OopClosure { | |
2002 bool _detected_scavenge_root; | |
2003 public: | |
2004 DetectScavengeRoot() : _detected_scavenge_root(false) | |
2005 { NOT_PRODUCT(_print_nm = NULL); } | |
2006 bool detected_scavenge_root() { return _detected_scavenge_root; } | |
2007 virtual void do_oop(oop* p) { | |
2008 if ((*p) != NULL && (*p)->is_scavengable()) { | |
2009 NOT_PRODUCT(maybe_print(p)); | |
2010 _detected_scavenge_root = true; | |
2011 } | |
2012 } | |
2013 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } | |
2014 | |
2015 #ifndef PRODUCT | |
2016 nmethod* _print_nm; | |
2017 void maybe_print(oop* p) { | |
2018 if (_print_nm == NULL) return; | |
2019 if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root"); | |
2020 tty->print_cr(""PTR_FORMAT"[offset=%d] detected scavengable oop "PTR_FORMAT" (found at "PTR_FORMAT")", | |
2021 _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm), | |
2022 (intptr_t)(*p), (intptr_t)p); | |
2023 (*p)->print(); | |
2024 } | |
2025 #endif //PRODUCT | |
2026 }; | |
2027 | |
2028 bool nmethod::detect_scavenge_root_oops() { | |
2029 DetectScavengeRoot detect_scavenge_root; | |
2030 NOT_PRODUCT(if (TraceScavenge) detect_scavenge_root._print_nm = this); | |
2031 oops_do(&detect_scavenge_root); | |
2032 return detect_scavenge_root.detected_scavenge_root(); | |
2033 } | |
2034 | |
2035 // Method that knows how to preserve outgoing arguments at call. This method must be | |
2036 // called with a frame corresponding to a Java invoke | |
2037 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { | |
2038 #ifndef SHARK | |
2039 if (!method()->is_native()) { | |
2040 SimpleScopeDesc ssd(this, fr.pc()); | |
2041 Bytecode_invoke call(ssd.method(), ssd.bci()); | |
2042 // compiled invokedynamic call sites have an implicit receiver at | |
2043 // resolution time, so make sure it gets GC'ed. | |
2044 bool has_receiver = !call.is_invokestatic(); | |
2045 Symbol* signature = call.signature(); | |
2046 fr.oops_compiled_arguments_do(signature, has_receiver, reg_map, f); | |
2047 } | |
2048 #endif // !SHARK | |
2049 } | |
2050 | |
2051 | |
2052 oop nmethod::embeddedOop_at(u_char* p) { | |
2053 RelocIterator iter(this, p, p + 1); | |
2054 while (iter.next()) | |
2055 if (iter.type() == relocInfo::oop_type) { | |
2056 return iter.oop_reloc()->oop_value(); | |
2057 } | |
2058 return NULL; | |
2059 } | |
2060 | |
2061 | |
2062 inline bool includes(void* p, void* from, void* to) { | |
2063 return from <= p && p < to; | |
2064 } | |
2065 | |
2066 | |
2067 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) { | |
2068 assert(count >= 2, "must be sentinel values, at least"); | |
2069 | |
2070 #ifdef ASSERT | |
2071 // must be sorted and unique; we do a binary search in find_pc_desc() | |
2072 int prev_offset = pcs[0].pc_offset(); | |
2073 assert(prev_offset == PcDesc::lower_offset_limit, | |
2074 "must start with a sentinel"); | |
2075 for (int i = 1; i < count; i++) { | |
2076 int this_offset = pcs[i].pc_offset(); | |
2077 assert(this_offset > prev_offset, "offsets must be sorted"); | |
2078 prev_offset = this_offset; | |
2079 } | |
2080 assert(prev_offset == PcDesc::upper_offset_limit, | |
2081 "must end with a sentinel"); | |
2082 #endif //ASSERT | |
2083 | |
2084 // Search for MethodHandle invokes and tag the nmethod. | |
2085 for (int i = 0; i < count; i++) { | |
2086 if (pcs[i].is_method_handle_invoke()) { | |
2087 set_has_method_handle_invokes(true); | |
2088 break; | |
2089 } | |
2090 } | |
2091 assert(has_method_handle_invokes() == (_deoptimize_mh_offset != -1), "must have deopt mh handler"); | |
2092 | |
2093 int size = count * sizeof(PcDesc); | |
2094 assert(scopes_pcs_size() >= size, "oob"); | |
2095 memcpy(scopes_pcs_begin(), pcs, size); | |
2096 | |
2097 // Adjust the final sentinel downward. | |
2098 PcDesc* last_pc = &scopes_pcs_begin()[count-1]; | |
2099 assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity"); | |
2100 last_pc->set_pc_offset(content_size() + 1); | |
2101 for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) { | |
2102 // Fill any rounding gaps with copies of the last record. | |
2103 last_pc[1] = last_pc[0]; | |
2104 } | |
2105 // The following assert could fail if sizeof(PcDesc) is not | |
2106 // an integral multiple of oopSize (the rounding term). | |
2107 // If it fails, change the logic to always allocate a multiple | |
2108 // of sizeof(PcDesc), and fill unused words with copies of *last_pc. | |
2109 assert(last_pc + 1 == scopes_pcs_end(), "must match exactly"); | |
2110 } | |
2111 | |
2112 void nmethod::copy_scopes_data(u_char* buffer, int size) { | |
2113 assert(scopes_data_size() >= size, "oob"); | |
2114 memcpy(scopes_data_begin(), buffer, size); | |
2115 } | |
2116 | |
2117 | |
2118 #ifdef ASSERT | |
2119 static PcDesc* linear_search(nmethod* nm, int pc_offset, bool approximate) { | |
2120 PcDesc* lower = nm->scopes_pcs_begin(); | |
2121 PcDesc* upper = nm->scopes_pcs_end(); | |
2122 lower += 1; // exclude initial sentinel | |
2123 PcDesc* res = NULL; | |
2124 for (PcDesc* p = lower; p < upper; p++) { | |
2125 NOT_PRODUCT(--nmethod_stats.pc_desc_tests); // don't count this call to match_desc | |
2126 if (match_desc(p, pc_offset, approximate)) { | |
2127 if (res == NULL) | |
2128 res = p; | |
2129 else | |
2130 res = (PcDesc*) badAddress; | |
2131 } | |
2132 } | |
2133 return res; | |
2134 } | |
2135 #endif | |
2136 | |
2137 | |
2138 // Finds a PcDesc with real-pc equal to "pc" | |
2139 PcDesc* nmethod::find_pc_desc_internal(address pc, bool approximate) { | |
2140 address base_address = code_begin(); | |
2141 if ((pc < base_address) || | |
2142 (pc - base_address) >= (ptrdiff_t) PcDesc::upper_offset_limit) { | |
2143 return NULL; // PC is wildly out of range | |
2144 } | |
2145 int pc_offset = (int) (pc - base_address); | |
2146 | |
2147 // Check the PcDesc cache if it contains the desired PcDesc | |
2148 // (This as an almost 100% hit rate.) | |
2149 PcDesc* res = _pc_desc_cache.find_pc_desc(pc_offset, approximate); | |
2150 if (res != NULL) { | |
2151 assert(res == linear_search(this, pc_offset, approximate), "cache ok"); | |
2152 return res; | |
2153 } | |
2154 | |
2155 // Fallback algorithm: quasi-linear search for the PcDesc | |
2156 // Find the last pc_offset less than the given offset. | |
2157 // The successor must be the required match, if there is a match at all. | |
2158 // (Use a fixed radix to avoid expensive affine pointer arithmetic.) | |
2159 PcDesc* lower = scopes_pcs_begin(); | |
2160 PcDesc* upper = scopes_pcs_end(); | |
2161 upper -= 1; // exclude final sentinel | |
2162 if (lower >= upper) return NULL; // native method; no PcDescs at all | |
2163 | |
2164 #define assert_LU_OK \ | |
2165 /* invariant on lower..upper during the following search: */ \ | |
2166 assert(lower->pc_offset() < pc_offset, "sanity"); \ | |
2167 assert(upper->pc_offset() >= pc_offset, "sanity") | |
2168 assert_LU_OK; | |
2169 | |
2170 // Use the last successful return as a split point. | |
2171 PcDesc* mid = _pc_desc_cache.last_pc_desc(); | |
2172 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); | |
2173 if (mid->pc_offset() < pc_offset) { | |
2174 lower = mid; | |
2175 } else { | |
2176 upper = mid; | |
2177 } | |
2178 | |
2179 // Take giant steps at first (4096, then 256, then 16, then 1) | |
2180 const int LOG2_RADIX = 4 /*smaller steps in debug mode:*/ debug_only(-1); | |
2181 const int RADIX = (1 << LOG2_RADIX); | |
2182 for (int step = (1 << (LOG2_RADIX*3)); step > 1; step >>= LOG2_RADIX) { | |
2183 while ((mid = lower + step) < upper) { | |
2184 assert_LU_OK; | |
2185 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); | |
2186 if (mid->pc_offset() < pc_offset) { | |
2187 lower = mid; | |
2188 } else { | |
2189 upper = mid; | |
2190 break; | |
2191 } | |
2192 } | |
2193 assert_LU_OK; | |
2194 } | |
2195 | |
2196 // Sneak up on the value with a linear search of length ~16. | |
2197 while (true) { | |
2198 assert_LU_OK; | |
2199 mid = lower + 1; | |
2200 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); | |
2201 if (mid->pc_offset() < pc_offset) { | |
2202 lower = mid; | |
2203 } else { | |
2204 upper = mid; | |
2205 break; | |
2206 } | |
2207 } | |
2208 #undef assert_LU_OK | |
2209 | |
2210 if (match_desc(upper, pc_offset, approximate)) { | |
2211 assert(upper == linear_search(this, pc_offset, approximate), "search ok"); | |
2212 _pc_desc_cache.add_pc_desc(upper); | |
2213 return upper; | |
2214 } else { | |
2215 assert(NULL == linear_search(this, pc_offset, approximate), "search ok"); | |
2216 return NULL; | |
2217 } | |
2218 } | |
2219 | |
2220 | |
2221 bool nmethod::check_all_dependencies() { | |
2222 bool found_check = false; | |
2223 // wholesale check of all dependencies | |
2224 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2225 if (deps.check_dependency() != NULL) { | |
2226 found_check = true; | |
2227 NOT_DEBUG(break); | |
2228 } | |
2229 } | |
2230 return found_check; // tell caller if we found anything | |
2231 } | |
2232 | |
2233 bool nmethod::check_dependency_on(DepChange& changes) { | |
2234 // What has happened: | |
2235 // 1) a new class dependee has been added | |
2236 // 2) dependee and all its super classes have been marked | |
2237 bool found_check = false; // set true if we are upset | |
2238 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2239 // Evaluate only relevant dependencies. | |
2240 if (deps.spot_check_dependency_at(changes) != NULL) { | |
2241 found_check = true; | |
2242 NOT_DEBUG(break); | |
2243 } | |
2244 } | |
2245 return found_check; | |
2246 } | |
2247 | |
2248 bool nmethod::is_evol_dependent_on(Klass* dependee) { | |
2249 InstanceKlass *dependee_ik = InstanceKlass::cast(dependee); | |
2250 Array<Method*>* dependee_methods = dependee_ik->methods(); | |
2251 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2252 if (deps.type() == Dependencies::evol_method) { | |
2253 Method* method = deps.method_argument(0); | |
2254 for (int j = 0; j < dependee_methods->length(); j++) { | |
2255 if (dependee_methods->at(j) == method) { | |
2256 // RC_TRACE macro has an embedded ResourceMark | |
2257 RC_TRACE(0x01000000, | |
2258 ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)", | |
2259 _method->method_holder()->external_name(), | |
2260 _method->name()->as_C_string(), | |
2261 _method->signature()->as_C_string(), compile_id(), | |
2262 method->method_holder()->external_name(), | |
2263 method->name()->as_C_string(), | |
2264 method->signature()->as_C_string())); | |
2265 if (TraceDependencies || LogCompilation) | |
2266 deps.log_dependency(dependee); | |
2267 return true; | |
2268 } | |
2269 } | |
2270 } | |
2271 } | |
2272 return false; | |
2273 } | |
2274 | |
2275 // Called from mark_for_deoptimization, when dependee is invalidated. | |
2276 bool nmethod::is_dependent_on_method(Method* dependee) { | |
2277 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2278 if (deps.type() != Dependencies::evol_method) | |
2279 continue; | |
2280 Method* method = deps.method_argument(0); | |
2281 if (method == dependee) return true; | |
2282 } | |
2283 return false; | |
2284 } | |
2285 | |
2286 | |
2287 bool nmethod::is_patchable_at(address instr_addr) { | |
2288 assert(insts_contains(instr_addr), "wrong nmethod used"); | |
2289 if (is_zombie()) { | |
2290 // a zombie may never be patched | |
2291 return false; | |
2292 } | |
2293 return true; | |
2294 } | |
2295 | |
2296 | |
2297 address nmethod::continuation_for_implicit_exception(address pc) { | |
2298 // Exception happened outside inline-cache check code => we are inside | |
2299 // an active nmethod => use cpc to determine a return address | |
2300 int exception_offset = pc - code_begin(); | |
2301 int cont_offset = ImplicitExceptionTable(this).at( exception_offset ); | |
2302 #ifdef ASSERT | |
2303 if (cont_offset == 0) { | |
2304 Thread* thread = ThreadLocalStorage::get_thread_slow(); | |
2305 ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY | |
2306 HandleMark hm(thread); | |
2307 ResourceMark rm(thread); | |
2308 CodeBlob* cb = CodeCache::find_blob(pc); | |
2309 assert(cb != NULL && cb == this, ""); | |
2310 tty->print_cr("implicit exception happened at " INTPTR_FORMAT, pc); | |
2311 print(); | |
2312 method()->print_codes(); | |
2313 print_code(); | |
2314 print_pcs(); | |
2315 } | |
2316 #endif | |
2317 if (cont_offset == 0) { | |
2318 // Let the normal error handling report the exception | |
2319 return NULL; | |
2320 } | |
2321 return code_begin() + cont_offset; | |
2322 } | |
2323 | |
2324 | |
2325 | |
2326 void nmethod_init() { | |
2327 // make sure you didn't forget to adjust the filler fields | |
2328 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word"); | |
2329 } | |
2330 | |
2331 | |
2332 //------------------------------------------------------------------------------------------- | |
2333 | |
2334 | |
2335 // QQQ might we make this work from a frame?? | |
2336 nmethodLocker::nmethodLocker(address pc) { | |
2337 CodeBlob* cb = CodeCache::find_blob(pc); | |
2338 guarantee(cb != NULL && cb->is_nmethod(), "bad pc for a nmethod found"); | |
2339 _nm = (nmethod*)cb; | |
2340 lock_nmethod(_nm); | |
2341 } | |
2342 | |
2343 // Only JvmtiDeferredEvent::compiled_method_unload_event() | |
2344 // should pass zombie_ok == true. | |
2345 void nmethodLocker::lock_nmethod(nmethod* nm, bool zombie_ok) { | |
2346 if (nm == NULL) return; | |
2347 Atomic::inc(&nm->_lock_count); | |
2348 guarantee(zombie_ok || !nm->is_zombie(), "cannot lock a zombie method"); | |
2349 } | |
2350 | |
2351 void nmethodLocker::unlock_nmethod(nmethod* nm) { | |
2352 if (nm == NULL) return; | |
2353 Atomic::dec(&nm->_lock_count); | |
2354 guarantee(nm->_lock_count >= 0, "unmatched nmethod lock/unlock"); | |
2355 } | |
2356 | |
2357 | |
2358 // ----------------------------------------------------------------------------- | |
2359 // nmethod::get_deopt_original_pc | |
2360 // | |
2361 // Return the original PC for the given PC if: | |
2362 // (a) the given PC belongs to a nmethod and | |
2363 // (b) it is a deopt PC | |
2364 address nmethod::get_deopt_original_pc(const frame* fr) { | |
2365 if (fr->cb() == NULL) return NULL; | |
2366 | |
2367 nmethod* nm = fr->cb()->as_nmethod_or_null(); | |
2368 if (nm != NULL && nm->is_deopt_pc(fr->pc())) | |
2369 return nm->get_original_pc(fr); | |
2370 | |
2371 return NULL; | |
2372 } | |
2373 | |
2374 | |
2375 // ----------------------------------------------------------------------------- | |
2376 // MethodHandle | |
2377 | |
2378 bool nmethod::is_method_handle_return(address return_pc) { | |
2379 if (!has_method_handle_invokes()) return false; | |
2380 PcDesc* pd = pc_desc_at(return_pc); | |
2381 if (pd == NULL) | |
2382 return false; | |
2383 return pd->is_method_handle_invoke(); | |
2384 } | |
2385 | |
2386 | |
2387 // ----------------------------------------------------------------------------- | |
2388 // Verification | |
2389 | |
2390 class VerifyOopsClosure: public OopClosure { | |
2391 nmethod* _nm; | |
2392 bool _ok; | |
2393 public: | |
2394 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { } | |
2395 bool ok() { return _ok; } | |
2396 virtual void do_oop(oop* p) { | |
2397 if ((*p) == NULL || (*p)->is_oop()) return; | |
2398 if (_ok) { | |
2399 _nm->print_nmethod(true); | |
2400 _ok = false; | |
2401 } | |
2402 tty->print_cr("*** non-oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", | |
2403 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); | |
2404 } | |
2405 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } | |
2406 }; | |
2407 | |
2408 void nmethod::verify() { | |
2409 | |
2410 // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant | |
2411 // seems odd. | |
2412 | |
2413 if( is_zombie() || is_not_entrant() ) | |
2414 return; | |
2415 | |
2416 // Make sure all the entry points are correctly aligned for patching. | |
2417 NativeJump::check_verified_entry_alignment(entry_point(), verified_entry_point()); | |
2418 | |
2419 // assert(method()->is_oop(), "must be valid"); | |
2420 | |
2421 ResourceMark rm; | |
2422 | |
2423 if (!CodeCache::contains(this)) { | |
2424 fatal(err_msg("nmethod at " INTPTR_FORMAT " not in zone", this)); | |
2425 } | |
2426 | |
2427 if(is_native_method() ) | |
2428 return; | |
2429 | |
2430 nmethod* nm = CodeCache::find_nmethod(verified_entry_point()); | |
2431 if (nm != this) { | |
2432 fatal(err_msg("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", | |
2433 this)); | |
2434 } | |
2435 | |
2436 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { | |
2437 if (! p->verify(this)) { | |
2438 tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", this); | |
2439 } | |
2440 } | |
2441 | |
2442 VerifyOopsClosure voc(this); | |
2443 oops_do(&voc); | |
2444 assert(voc.ok(), "embedded oops must be OK"); | |
2445 verify_scavenge_root_oops(); | |
2446 | |
2447 verify_scopes(); | |
2448 } | |
2449 | |
2450 | |
2451 void nmethod::verify_interrupt_point(address call_site) { | |
2452 // This code does not work in release mode since | |
2453 // owns_lock only is available in debug mode. | |
2454 CompiledIC* ic = NULL; | |
2455 Thread *cur = Thread::current(); | |
2456 if (CompiledIC_lock->owner() == cur || | |
2457 ((cur->is_VM_thread() || cur->is_ConcurrentGC_thread()) && | |
2458 SafepointSynchronize::is_at_safepoint())) { | |
2459 ic = CompiledIC_at(this, call_site); | |
2460 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); | |
2461 } else { | |
2462 MutexLocker ml_verify (CompiledIC_lock); | |
2463 ic = CompiledIC_at(this, call_site); | |
2464 } | |
2465 PcDesc* pd = pc_desc_at(ic->end_of_call()); | |
2466 assert(pd != NULL, "PcDesc must exist"); | |
2467 for (ScopeDesc* sd = new ScopeDesc(this, pd->scope_decode_offset(), | |
2468 pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), | |
2469 pd->return_oop()); | |
2470 !sd->is_top(); sd = sd->sender()) { | |
2471 sd->verify(); | |
2472 } | |
2473 } | |
2474 | |
2475 void nmethod::verify_scopes() { | |
2476 if( !method() ) return; // Runtime stubs have no scope | |
2477 if (method()->is_native()) return; // Ignore stub methods. | |
2478 // iterate through all interrupt point | |
2479 // and verify the debug information is valid. | |
2480 RelocIterator iter((nmethod*)this); | |
2481 while (iter.next()) { | |
2482 address stub = NULL; | |
2483 switch (iter.type()) { | |
2484 case relocInfo::virtual_call_type: | |
2485 verify_interrupt_point(iter.addr()); | |
2486 break; | |
2487 case relocInfo::opt_virtual_call_type: | |
2488 stub = iter.opt_virtual_call_reloc()->static_stub(); | |
2489 verify_interrupt_point(iter.addr()); | |
2490 break; | |
2491 case relocInfo::static_call_type: | |
2492 stub = iter.static_call_reloc()->static_stub(); | |
2493 //verify_interrupt_point(iter.addr()); | |
2494 break; | |
2495 case relocInfo::runtime_call_type: | |
2496 address destination = iter.reloc()->value(); | |
2497 // Right now there is no way to find out which entries support | |
2498 // an interrupt point. It would be nice if we had this | |
2499 // information in a table. | |
2500 break; | |
2501 } | |
2502 #ifndef GRAAL | |
2503 assert(stub == NULL || stub_contains(stub), "static call stub outside stub section"); | |
2504 #endif | |
2505 } | |
2506 } | |
2507 | |
2508 | |
2509 // ----------------------------------------------------------------------------- | |
2510 // Non-product code | |
2511 #ifndef PRODUCT | |
2512 | |
2513 class DebugScavengeRoot: public OopClosure { | |
2514 nmethod* _nm; | |
2515 bool _ok; | |
2516 public: | |
2517 DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { } | |
2518 bool ok() { return _ok; } | |
2519 virtual void do_oop(oop* p) { | |
2520 if ((*p) == NULL || !(*p)->is_scavengable()) return; | |
2521 if (_ok) { | |
2522 _nm->print_nmethod(true); | |
2523 _ok = false; | |
2524 } | |
2525 tty->print_cr("*** scavengable oop "PTR_FORMAT" found at "PTR_FORMAT" (offset %d)", | |
2526 (intptr_t)(*p), (intptr_t)p, (int)((intptr_t)p - (intptr_t)_nm)); | |
2527 (*p)->print(); | |
2528 } | |
2529 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } | |
2530 }; | |
2531 | |
2532 void nmethod::verify_scavenge_root_oops() { | |
2533 if (!on_scavenge_root_list()) { | |
2534 // Actually look inside, to verify the claim that it's clean. | |
2535 DebugScavengeRoot debug_scavenge_root(this); | |
2536 oops_do(&debug_scavenge_root); | |
2537 if (!debug_scavenge_root.ok()) | |
2538 fatal("found an unadvertised bad scavengable oop in the code cache"); | |
2539 } | |
2540 assert(scavenge_root_not_marked(), ""); | |
2541 } | |
2542 | |
2543 #endif // PRODUCT | |
2544 | |
2545 // Printing operations | |
2546 | |
2547 void nmethod::print() const { | |
2548 ResourceMark rm; | |
2549 ttyLocker ttyl; // keep the following output all in one block | |
2550 | |
2551 tty->print("Compiled method "); | |
2552 | |
2553 if (is_compiled_by_c1()) { | |
2554 tty->print("(c1) "); | |
2555 } else if (is_compiled_by_c2()) { | |
2556 tty->print("(c2) "); | |
2557 } else if (is_compiled_by_shark()) { | |
2558 tty->print("(shark) "); | |
7125
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
2559 } else if (is_compiled_by_graal()) { |
1baf7f1e3f23
decoupled C++ Graal runtime from C1
Doug Simon <doug.simon@oracle.com>
parents:
7112
diff
changeset
|
2560 tty->print("(Graal) "); |
7066 | 2561 } else { |
2562 tty->print("(nm) "); | |
2563 } | |
2564 | |
2565 print_on(tty, NULL); | |
2566 | |
2567 if (WizardMode) { | |
2568 tty->print("((nmethod*) "INTPTR_FORMAT ") ", this); | |
2569 tty->print(" for method " INTPTR_FORMAT , (address)method()); | |
2570 tty->print(" { "); | |
2571 if (is_in_use()) tty->print("in_use "); | |
2572 if (is_not_entrant()) tty->print("not_entrant "); | |
2573 if (is_zombie()) tty->print("zombie "); | |
2574 if (is_unloaded()) tty->print("unloaded "); | |
2575 if (on_scavenge_root_list()) tty->print("scavenge_root "); | |
2576 tty->print_cr("}:"); | |
2577 } | |
2578 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2579 (address)this, | |
2580 (address)this + size(), | |
2581 size()); | |
2582 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2583 relocation_begin(), | |
2584 relocation_end(), | |
2585 relocation_size()); | |
2586 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2587 consts_begin(), | |
2588 consts_end(), | |
2589 consts_size()); | |
2590 if (insts_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2591 insts_begin(), | |
2592 insts_end(), | |
2593 insts_size()); | |
2594 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2595 stub_begin(), | |
2596 stub_end(), | |
2597 stub_size()); | |
2598 if (oops_size () > 0) tty->print_cr(" oops [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2599 oops_begin(), | |
2600 oops_end(), | |
2601 oops_size()); | |
2602 if (metadata_size () > 0) tty->print_cr(" metadata [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2603 metadata_begin(), | |
2604 metadata_end(), | |
2605 metadata_size()); | |
2606 if (scopes_data_size () > 0) tty->print_cr(" scopes data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2607 scopes_data_begin(), | |
2608 scopes_data_end(), | |
2609 scopes_data_size()); | |
2610 if (scopes_pcs_size () > 0) tty->print_cr(" scopes pcs [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2611 scopes_pcs_begin(), | |
2612 scopes_pcs_end(), | |
2613 scopes_pcs_size()); | |
2614 if (dependencies_size () > 0) tty->print_cr(" dependencies [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2615 dependencies_begin(), | |
2616 dependencies_end(), | |
2617 dependencies_size()); | |
2618 if (handler_table_size() > 0) tty->print_cr(" handler table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2619 handler_table_begin(), | |
2620 handler_table_end(), | |
2621 handler_table_size()); | |
2622 if (nul_chk_table_size() > 0) tty->print_cr(" nul chk table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2623 nul_chk_table_begin(), | |
2624 nul_chk_table_end(), | |
2625 nul_chk_table_size()); | |
2626 } | |
2627 | |
2628 void nmethod::print_code() { | |
2629 HandleMark hm; | |
2630 ResourceMark m; | |
2631 Disassembler::decode(this); | |
2632 } | |
2633 | |
2634 | |
2635 #ifndef PRODUCT | |
2636 | |
2637 void nmethod::print_scopes() { | |
2638 // Find the first pc desc for all scopes in the code and print it. | |
2639 ResourceMark rm; | |
2640 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { | |
2641 if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null) | |
2642 continue; | |
2643 | |
2644 ScopeDesc* sd = scope_desc_at(p->real_pc(this)); | |
2645 sd->print_on(tty, p); | |
2646 } | |
2647 } | |
2648 | |
2649 void nmethod::print_dependencies() { | |
2650 ResourceMark rm; | |
2651 ttyLocker ttyl; // keep the following output all in one block | |
2652 tty->print_cr("Dependencies:"); | |
2653 for (Dependencies::DepStream deps(this); deps.next(); ) { | |
2654 deps.print_dependency(); | |
2655 Klass* ctxk = deps.context_type(); | |
2656 if (ctxk != NULL) { | |
2657 if (ctxk->oop_is_instance() && ((InstanceKlass*)ctxk)->is_dependent_nmethod(this)) { | |
2658 tty->print_cr(" [nmethod<=klass]%s", ctxk->external_name()); | |
2659 } | |
2660 } | |
2661 deps.log_dependency(); // put it into the xml log also | |
2662 } | |
2663 } | |
2664 | |
2665 | |
2666 void nmethod::print_relocations() { | |
2667 ResourceMark m; // in case methods get printed via the debugger | |
2668 tty->print_cr("relocations:"); | |
2669 RelocIterator iter(this); | |
2670 iter.print(); | |
2671 if (UseRelocIndex) { | |
2672 jint* index_end = (jint*)relocation_end() - 1; | |
2673 jint index_size = *index_end; | |
2674 jint* index_start = (jint*)( (address)index_end - index_size ); | |
2675 tty->print_cr(" index @" INTPTR_FORMAT ": index_size=%d", index_start, index_size); | |
2676 if (index_size > 0) { | |
2677 jint* ip; | |
2678 for (ip = index_start; ip+2 <= index_end; ip += 2) | |
2679 tty->print_cr(" (%d %d) addr=" INTPTR_FORMAT " @" INTPTR_FORMAT, | |
2680 ip[0], | |
2681 ip[1], | |
2682 header_end()+ip[0], | |
2683 relocation_begin()-1+ip[1]); | |
2684 for (; ip < index_end; ip++) | |
2685 tty->print_cr(" (%d ?)", ip[0]); | |
2686 tty->print_cr(" @" INTPTR_FORMAT ": index_size=%d", ip, *ip++); | |
2687 tty->print_cr("reloc_end @" INTPTR_FORMAT ":", ip); | |
2688 } | |
2689 } | |
2690 } | |
2691 | |
2692 | |
2693 void nmethod::print_pcs() { | |
2694 ResourceMark m; // in case methods get printed via debugger | |
2695 tty->print_cr("pc-bytecode offsets:"); | |
2696 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { | |
2697 p->print(this); | |
2698 } | |
2699 } | |
2700 | |
2701 #endif // PRODUCT | |
2702 | |
2703 const char* nmethod::reloc_string_for(u_char* begin, u_char* end) { | |
2704 RelocIterator iter(this, begin, end); | |
2705 bool have_one = false; | |
2706 while (iter.next()) { | |
2707 have_one = true; | |
2708 switch (iter.type()) { | |
2709 case relocInfo::none: return "no_reloc"; | |
2710 case relocInfo::oop_type: { | |
2711 stringStream st; | |
2712 oop_Relocation* r = iter.oop_reloc(); | |
2713 oop obj = r->oop_value(); | |
2714 st.print("oop("); | |
2715 if (obj == NULL) st.print("NULL"); | |
2716 else obj->print_value_on(&st); | |
2717 st.print(")"); | |
2718 return st.as_string(); | |
2719 } | |
2720 case relocInfo::metadata_type: { | |
2721 stringStream st; | |
2722 metadata_Relocation* r = iter.metadata_reloc(); | |
2723 Metadata* obj = r->metadata_value(); | |
2724 st.print("metadata("); | |
2725 if (obj == NULL) st.print("NULL"); | |
2726 else obj->print_value_on(&st); | |
2727 st.print(")"); | |
2728 return st.as_string(); | |
2729 } | |
2730 case relocInfo::virtual_call_type: return "virtual_call"; | |
2731 case relocInfo::opt_virtual_call_type: return "optimized virtual_call"; | |
2732 case relocInfo::static_call_type: return "static_call"; | |
2733 case relocInfo::static_stub_type: return "static_stub"; | |
2734 case relocInfo::runtime_call_type: return "runtime_call"; | |
2735 case relocInfo::external_word_type: return "external_word"; | |
2736 case relocInfo::internal_word_type: return "internal_word"; | |
2737 case relocInfo::section_word_type: return "section_word"; | |
2738 case relocInfo::poll_type: return "poll"; | |
2739 case relocInfo::poll_return_type: return "poll_return"; | |
2740 case relocInfo::type_mask: return "type_bit_mask"; | |
2741 } | |
2742 } | |
2743 return have_one ? "other" : NULL; | |
2744 } | |
2745 | |
2746 // Return a the last scope in (begin..end] | |
2747 ScopeDesc* nmethod::scope_desc_in(address begin, address end) { | |
2748 PcDesc* p = pc_desc_near(begin+1); | |
2749 if (p != NULL && p->real_pc(this) <= end) { | |
2750 return new ScopeDesc(this, p->scope_decode_offset(), | |
2751 p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(), | |
2752 p->return_oop()); | |
2753 } | |
2754 return NULL; | |
2755 } | |
2756 | |
2757 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin) const { | |
2758 if (block_begin == entry_point()) stream->print_cr("[Entry Point]"); | |
2759 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]"); | |
2760 if (GRAAL_ONLY(_exception_offset >= 0 &&) block_begin == exception_begin()) stream->print_cr("[Exception Handler]"); | |
2761 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]"); | |
2762 if (GRAAL_ONLY(_deoptimize_offset >= 0 &&) block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]"); | |
2763 | |
2764 if (has_method_handle_invokes()) | |
2765 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]"); | |
2766 | |
2767 if (block_begin == consts_begin()) stream->print_cr("[Constants]"); | |
2768 | |
2769 if (block_begin == entry_point()) { | |
2770 methodHandle m = method(); | |
2771 if (m.not_null()) { | |
2772 stream->print(" # "); | |
2773 m->print_value_on(stream); | |
2774 stream->cr(); | |
2775 } | |
2776 if (m.not_null() && !is_osr_method()) { | |
2777 ResourceMark rm; | |
2778 int sizeargs = m->size_of_parameters(); | |
2779 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs); | |
2780 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs); | |
2781 { | |
2782 int sig_index = 0; | |
2783 if (!m->is_static()) | |
2784 sig_bt[sig_index++] = T_OBJECT; // 'this' | |
2785 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) { | |
2786 BasicType t = ss.type(); | |
2787 sig_bt[sig_index++] = t; | |
2788 if (type2size[t] == 2) { | |
2789 sig_bt[sig_index++] = T_VOID; | |
2790 } else { | |
2791 assert(type2size[t] == 1, "size is 1 or 2"); | |
2792 } | |
2793 } | |
2794 assert(sig_index == sizeargs, ""); | |
2795 } | |
2796 const char* spname = "sp"; // make arch-specific? | |
2797 intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, false); | |
2798 int stack_slot_offset = this->frame_size() * wordSize; | |
2799 int tab1 = 14, tab2 = 24; | |
2800 int sig_index = 0; | |
2801 int arg_index = (m->is_static() ? 0 : -1); | |
2802 bool did_old_sp = false; | |
2803 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) { | |
2804 bool at_this = (arg_index == -1); | |
2805 bool at_old_sp = false; | |
2806 BasicType t = (at_this ? T_OBJECT : ss.type()); | |
2807 assert(t == sig_bt[sig_index], "sigs in sync"); | |
2808 if (at_this) | |
2809 stream->print(" # this: "); | |
2810 else | |
2811 stream->print(" # parm%d: ", arg_index); | |
2812 stream->move_to(tab1); | |
2813 VMReg fst = regs[sig_index].first(); | |
2814 VMReg snd = regs[sig_index].second(); | |
2815 if (fst->is_reg()) { | |
2816 stream->print("%s", fst->name()); | |
2817 if (snd->is_valid()) { | |
2818 stream->print(":%s", snd->name()); | |
2819 } | |
2820 } else if (fst->is_stack()) { | |
2821 int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset; | |
2822 if (offset == stack_slot_offset) at_old_sp = true; | |
2823 stream->print("[%s+0x%x]", spname, offset); | |
2824 } else { | |
2825 stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd); | |
2826 } | |
2827 stream->print(" "); | |
2828 stream->move_to(tab2); | |
2829 stream->print("= "); | |
2830 if (at_this) { | |
2831 m->method_holder()->print_value_on(stream); | |
2832 } else { | |
2833 bool did_name = false; | |
2834 if (!at_this && ss.is_object()) { | |
2835 Symbol* name = ss.as_symbol_or_null(); | |
2836 if (name != NULL) { | |
2837 name->print_value_on(stream); | |
2838 did_name = true; | |
2839 } | |
2840 } | |
2841 if (!did_name) | |
2842 stream->print("%s", type2name(t)); | |
2843 } | |
2844 if (at_old_sp) { | |
2845 stream->print(" (%s of caller)", spname); | |
2846 did_old_sp = true; | |
2847 } | |
2848 stream->cr(); | |
2849 sig_index += type2size[t]; | |
2850 arg_index += 1; | |
2851 if (!at_this) ss.next(); | |
2852 } | |
2853 if (!did_old_sp) { | |
2854 stream->print(" # "); | |
2855 stream->move_to(tab1); | |
2856 stream->print("[%s+0x%x]", spname, stack_slot_offset); | |
2857 stream->print(" (%s of caller)", spname); | |
2858 stream->cr(); | |
2859 } | |
2860 } | |
2861 } | |
2862 } | |
2863 | |
2864 void nmethod::print_code_comment_on(outputStream* st, int column, u_char* begin, u_char* end) { | |
2865 // First, find an oopmap in (begin, end]. | |
2866 // We use the odd half-closed interval so that oop maps and scope descs | |
2867 // which are tied to the byte after a call are printed with the call itself. | |
2868 address base = code_begin(); | |
2869 OopMapSet* oms = oop_maps(); | |
2870 if (oms != NULL) { | |
2871 for (int i = 0, imax = oms->size(); i < imax; i++) { | |
2872 OopMap* om = oms->at(i); | |
2873 address pc = base + om->offset(); | |
2874 if (pc > begin) { | |
2875 if (pc <= end) { | |
2876 st->move_to(column); | |
2877 st->print("; "); | |
2878 om->print_on(st); | |
2879 } | |
2880 break; | |
2881 } | |
2882 } | |
2883 } | |
2884 | |
2885 // Print any debug info present at this pc. | |
2886 ScopeDesc* sd = scope_desc_in(begin, end); | |
2887 if (sd != NULL) { | |
2888 st->move_to(column); | |
2889 if (sd->bci() == SynchronizationEntryBCI) { | |
2890 st->print(";*synchronization entry"); | |
2891 } else { | |
2892 if (sd->method() == NULL) { | |
2893 st->print("method is NULL"); | |
2894 } else if (sd->method()->is_native()) { | |
2895 st->print("method is native"); | |
2896 } else { | |
2897 Bytecodes::Code bc = sd->method()->java_code_at(sd->bci()); | |
2898 st->print(";*%s", Bytecodes::name(bc)); | |
2899 switch (bc) { | |
2900 case Bytecodes::_invokevirtual: | |
2901 case Bytecodes::_invokespecial: | |
2902 case Bytecodes::_invokestatic: | |
2903 case Bytecodes::_invokeinterface: | |
2904 { | |
2905 Bytecode_invoke invoke(sd->method(), sd->bci()); | |
2906 st->print(" "); | |
2907 if (invoke.name() != NULL) | |
2908 invoke.name()->print_symbol_on(st); | |
2909 else | |
2910 st->print("<UNKNOWN>"); | |
2911 break; | |
2912 } | |
2913 case Bytecodes::_getfield: | |
2914 case Bytecodes::_putfield: | |
2915 case Bytecodes::_getstatic: | |
2916 case Bytecodes::_putstatic: | |
2917 { | |
2918 Bytecode_field field(sd->method(), sd->bci()); | |
2919 st->print(" "); | |
2920 if (field.name() != NULL) | |
2921 field.name()->print_symbol_on(st); | |
2922 else | |
2923 st->print("<UNKNOWN>"); | |
2924 } | |
2925 } | |
2926 } | |
2927 } | |
2928 | |
2929 // Print all scopes | |
2930 for (;sd != NULL; sd = sd->sender()) { | |
2931 st->move_to(column); | |
2932 st->print("; -"); | |
2933 if (sd->method() == NULL) { | |
2934 st->print("method is NULL"); | |
2935 } else { | |
2936 sd->method()->print_short_name(st); | |
2937 } | |
2938 int lineno = sd->method()->line_number_from_bci(sd->bci()); | |
2939 if (lineno != -1) { | |
2940 st->print("@%d (line %d)", sd->bci(), lineno); | |
2941 } else { | |
2942 st->print("@%d", sd->bci()); | |
2943 } | |
2944 st->cr(); | |
2945 } | |
2946 } | |
2947 | |
2948 // Print relocation information | |
2949 const char* str = reloc_string_for(begin, end); | |
2950 if (str != NULL) { | |
2951 if (sd != NULL) st->cr(); | |
2952 st->move_to(column); | |
2953 st->print("; {%s}", str); | |
2954 } | |
2955 int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin()); | |
2956 if (cont_offset != 0) { | |
2957 st->move_to(column); | |
2958 st->print("; implicit exception: dispatches to " INTPTR_FORMAT, code_begin() + cont_offset); | |
2959 } | |
2960 | |
2961 } | |
2962 | |
2963 #ifndef PRODUCT | |
2964 | |
2965 void nmethod::print_value_on(outputStream* st) const { | |
2966 st->print("nmethod"); | |
2967 print_on(st, NULL); | |
2968 } | |
2969 | |
2970 void nmethod::print_calls(outputStream* st) { | |
2971 RelocIterator iter(this); | |
2972 while (iter.next()) { | |
2973 switch (iter.type()) { | |
2974 case relocInfo::virtual_call_type: | |
2975 case relocInfo::opt_virtual_call_type: { | |
2976 VerifyMutexLocker mc(CompiledIC_lock); | |
2977 CompiledIC_at(iter.reloc())->print(); | |
2978 break; | |
2979 } | |
2980 case relocInfo::static_call_type: | |
2981 st->print_cr("Static call at " INTPTR_FORMAT, iter.reloc()->addr()); | |
2982 compiledStaticCall_at(iter.reloc())->print(); | |
2983 break; | |
2984 } | |
2985 } | |
2986 } | |
2987 | |
2988 void nmethod::print_handler_table() { | |
2989 ExceptionHandlerTable(this).print(); | |
2990 } | |
2991 | |
2992 void nmethod::print_nul_chk_table() { | |
2993 ImplicitExceptionTable(this).print(code_begin()); | |
2994 } | |
2995 | |
2996 #endif // PRODUCT | |
2997 | |
2998 void nmethod::print_statistics() { | |
2999 ttyLocker ttyl; | |
3000 if (xtty != NULL) xtty->head("statistics type='nmethod'"); | |
3001 nmethod_stats.print_native_nmethod_stats(); | |
3002 nmethod_stats.print_nmethod_stats(); | |
3003 DebugInformationRecorder::print_statistics(); | |
3004 nmethod_stats.print_pc_stats(); | |
3005 Dependencies::print_statistics(); | |
3006 if (xtty != NULL) xtty->tail("statistics"); | |
3007 } | |
3008 | |
3009 #ifdef GRAAL | |
3010 void DebugScopedNMethod::print_on(outputStream* st) { | |
3011 if (_nm != NULL) { | |
3012 st->print("nmethod@%p", _nm); | |
3013 Method* method = _nm->method(); | |
3014 if (method != NULL) { | |
3015 char holder[O_BUFLEN]; | |
3016 char nameAndSig[O_BUFLEN]; | |
3017 method->method_holder()->name()->as_C_string(holder, O_BUFLEN); | |
3018 method->name_and_sig_as_C_string(nameAndSig, O_BUFLEN); | |
3019 st->print(" - %s::%s", holder, nameAndSig); | |
3020 } | |
3021 } | |
3022 } | |
3023 #endif |