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