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