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