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