changeset 33198 | b37ad9fbf681 |
parent 33148 | 68fa8b6c4340 |
parent 33160 | c59f1676d27e |
child 33451 | 0712796e4039 |
child 33576 | 6dbde58b08a6 |
33155:73bf16b22e89 | 33198:b37ad9fbf681 |
---|---|
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "code/codeCache.hpp" |
26 #include "code/codeCache.hpp" |
27 #include "code/compiledIC.hpp" |
27 #include "code/compiledIC.hpp" |
28 #include "code/dependencies.hpp" |
28 #include "code/dependencies.hpp" |
29 #include "code/nativeInst.hpp" |
|
29 #include "code/nmethod.hpp" |
30 #include "code/nmethod.hpp" |
30 #include "code/scopeDesc.hpp" |
31 #include "code/scopeDesc.hpp" |
31 #include "compiler/abstractCompiler.hpp" |
32 #include "compiler/abstractCompiler.hpp" |
32 #include "compiler/compileBroker.hpp" |
33 #include "compiler/compileBroker.hpp" |
33 #include "compiler/compileLog.hpp" |
34 #include "compiler/compileLog.hpp" |
44 #include "runtime/sweeper.hpp" |
45 #include "runtime/sweeper.hpp" |
45 #include "utilities/resourceHash.hpp" |
46 #include "utilities/resourceHash.hpp" |
46 #include "utilities/dtrace.hpp" |
47 #include "utilities/dtrace.hpp" |
47 #include "utilities/events.hpp" |
48 #include "utilities/events.hpp" |
48 #include "utilities/xmlstream.hpp" |
49 #include "utilities/xmlstream.hpp" |
50 #ifdef TARGET_ARCH_x86 |
|
51 # include "nativeInst_x86.hpp" |
|
52 #endif |
|
53 #ifdef TARGET_ARCH_sparc |
|
54 # include "nativeInst_sparc.hpp" |
|
55 #endif |
|
56 #ifdef TARGET_ARCH_zero |
|
57 # include "nativeInst_zero.hpp" |
|
58 #endif |
|
59 #ifdef TARGET_ARCH_arm |
|
60 # include "nativeInst_arm.hpp" |
|
61 #endif |
|
62 #ifdef TARGET_ARCH_ppc |
|
63 # include "nativeInst_ppc.hpp" |
|
64 #endif |
|
49 #ifdef SHARK |
65 #ifdef SHARK |
50 #include "shark/sharkCompiler.hpp" |
66 #include "shark/sharkCompiler.hpp" |
67 #endif |
|
68 #if INCLUDE_JVMCI |
|
69 #include "jvmci/jvmciJavaClasses.hpp" |
|
51 #endif |
70 #endif |
52 |
71 |
53 unsigned char nmethod::_global_unloading_clock = 0; |
72 unsigned char nmethod::_global_unloading_clock = 0; |
54 |
73 |
55 #ifdef DTRACE_ENABLED |
74 #ifdef DTRACE_ENABLED |
80 if (compiler() == NULL) { |
99 if (compiler() == NULL) { |
81 return false; |
100 return false; |
82 } |
101 } |
83 return compiler()->is_c1(); |
102 return compiler()->is_c1(); |
84 } |
103 } |
104 bool nmethod::is_compiled_by_jvmci() const { |
|
105 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing |
|
106 if (is_native_method()) return false; |
|
107 return compiler()->is_jvmci(); |
|
108 } |
|
85 bool nmethod::is_compiled_by_c2() const { |
109 bool nmethod::is_compiled_by_c2() const { |
86 if (compiler() == NULL) { |
110 if (compiler() == NULL) { |
87 return false; |
111 return false; |
88 } |
112 } |
89 return compiler()->is_c2(); |
113 return compiler()->is_c2(); |
104 // (In the latter two cases, they like other stats are printed to the log only.) |
128 // (In the latter two cases, they like other stats are printed to the log only.) |
105 |
129 |
106 #ifndef PRODUCT |
130 #ifndef PRODUCT |
107 // These variables are put into one block to reduce relocations |
131 // These variables are put into one block to reduce relocations |
108 // and make it simpler to print from the debugger. |
132 // and make it simpler to print from the debugger. |
109 static |
133 struct java_nmethod_stats_struct { |
110 struct nmethod_stats_struct { |
|
111 int nmethod_count; |
134 int nmethod_count; |
112 int total_size; |
135 int total_size; |
113 int relocation_size; |
136 int relocation_size; |
114 int consts_size; |
137 int consts_size; |
115 int insts_size; |
138 int insts_size; |
118 int scopes_pcs_size; |
141 int scopes_pcs_size; |
119 int dependencies_size; |
142 int dependencies_size; |
120 int handler_table_size; |
143 int handler_table_size; |
121 int nul_chk_table_size; |
144 int nul_chk_table_size; |
122 int oops_size; |
145 int oops_size; |
146 int metadata_size; |
|
123 |
147 |
124 void note_nmethod(nmethod* nm) { |
148 void note_nmethod(nmethod* nm) { |
125 nmethod_count += 1; |
149 nmethod_count += 1; |
126 total_size += nm->size(); |
150 total_size += nm->size(); |
127 relocation_size += nm->relocation_size(); |
151 relocation_size += nm->relocation_size(); |
128 consts_size += nm->consts_size(); |
152 consts_size += nm->consts_size(); |
129 insts_size += nm->insts_size(); |
153 insts_size += nm->insts_size(); |
130 stub_size += nm->stub_size(); |
154 stub_size += nm->stub_size(); |
131 oops_size += nm->oops_size(); |
155 oops_size += nm->oops_size(); |
156 metadata_size += nm->metadata_size(); |
|
132 scopes_data_size += nm->scopes_data_size(); |
157 scopes_data_size += nm->scopes_data_size(); |
133 scopes_pcs_size += nm->scopes_pcs_size(); |
158 scopes_pcs_size += nm->scopes_pcs_size(); |
134 dependencies_size += nm->dependencies_size(); |
159 dependencies_size += nm->dependencies_size(); |
135 handler_table_size += nm->handler_table_size(); |
160 handler_table_size += nm->handler_table_size(); |
136 nul_chk_table_size += nm->nul_chk_table_size(); |
161 nul_chk_table_size += nm->nul_chk_table_size(); |
137 } |
162 } |
138 void print_nmethod_stats() { |
163 void print_nmethod_stats(const char* name) { |
139 if (nmethod_count == 0) return; |
164 if (nmethod_count == 0) return; |
140 tty->print_cr("Statistics for %d bytecoded nmethods:", nmethod_count); |
165 tty->print_cr("Statistics for %d bytecoded nmethods for %s:", nmethod_count, name); |
141 if (total_size != 0) tty->print_cr(" total in heap = %d", total_size); |
166 if (total_size != 0) tty->print_cr(" total in heap = %d", total_size); |
167 if (nmethod_count != 0) tty->print_cr(" header = " SIZE_FORMAT, nmethod_count * sizeof(nmethod)); |
|
142 if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size); |
168 if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size); |
143 if (consts_size != 0) tty->print_cr(" constants = %d", consts_size); |
169 if (consts_size != 0) tty->print_cr(" constants = %d", consts_size); |
144 if (insts_size != 0) tty->print_cr(" main code = %d", insts_size); |
170 if (insts_size != 0) tty->print_cr(" main code = %d", insts_size); |
145 if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size); |
171 if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size); |
146 if (oops_size != 0) tty->print_cr(" oops = %d", oops_size); |
172 if (oops_size != 0) tty->print_cr(" oops = %d", oops_size); |
173 if (metadata_size != 0) tty->print_cr(" metadata = %d", metadata_size); |
|
147 if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size); |
174 if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size); |
148 if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size); |
175 if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size); |
149 if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size); |
176 if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size); |
150 if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size); |
177 if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size); |
151 if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size); |
178 if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size); |
152 } |
179 } |
153 |
180 }; |
181 |
|
182 struct native_nmethod_stats_struct { |
|
154 int native_nmethod_count; |
183 int native_nmethod_count; |
155 int native_total_size; |
184 int native_total_size; |
156 int native_relocation_size; |
185 int native_relocation_size; |
157 int native_insts_size; |
186 int native_insts_size; |
158 int native_oops_size; |
187 int native_oops_size; |
188 int native_metadata_size; |
|
159 void note_native_nmethod(nmethod* nm) { |
189 void note_native_nmethod(nmethod* nm) { |
160 native_nmethod_count += 1; |
190 native_nmethod_count += 1; |
161 native_total_size += nm->size(); |
191 native_total_size += nm->size(); |
162 native_relocation_size += nm->relocation_size(); |
192 native_relocation_size += nm->relocation_size(); |
163 native_insts_size += nm->insts_size(); |
193 native_insts_size += nm->insts_size(); |
164 native_oops_size += nm->oops_size(); |
194 native_oops_size += nm->oops_size(); |
195 native_metadata_size += nm->metadata_size(); |
|
165 } |
196 } |
166 void print_native_nmethod_stats() { |
197 void print_native_nmethod_stats() { |
167 if (native_nmethod_count == 0) return; |
198 if (native_nmethod_count == 0) return; |
168 tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count); |
199 tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count); |
169 if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size); |
200 if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size); |
170 if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size); |
201 if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size); |
171 if (native_insts_size != 0) tty->print_cr(" N. main code = %d", native_insts_size); |
202 if (native_insts_size != 0) tty->print_cr(" N. main code = %d", native_insts_size); |
172 if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size); |
203 if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size); |
173 } |
204 if (native_metadata_size != 0) tty->print_cr(" N. metadata = %d", native_metadata_size); |
174 |
205 } |
206 }; |
|
207 |
|
208 struct pc_nmethod_stats_struct { |
|
175 int pc_desc_resets; // number of resets (= number of caches) |
209 int pc_desc_resets; // number of resets (= number of caches) |
176 int pc_desc_queries; // queries to nmethod::find_pc_desc |
210 int pc_desc_queries; // queries to nmethod::find_pc_desc |
177 int pc_desc_approx; // number of those which have approximate true |
211 int pc_desc_approx; // number of those which have approximate true |
178 int pc_desc_repeats; // number of _pc_descs[0] hits |
212 int pc_desc_repeats; // number of _pc_descs[0] hits |
179 int pc_desc_hits; // number of LRU cache hits |
213 int pc_desc_hits; // number of LRU cache hits |
190 pc_desc_resets, |
224 pc_desc_resets, |
191 pc_desc_queries, pc_desc_approx, |
225 pc_desc_queries, pc_desc_approx, |
192 pc_desc_repeats, pc_desc_hits, |
226 pc_desc_repeats, pc_desc_hits, |
193 pc_desc_tests, pc_desc_searches, pc_desc_adds); |
227 pc_desc_tests, pc_desc_searches, pc_desc_adds); |
194 } |
228 } |
195 } nmethod_stats; |
229 }; |
196 #endif //PRODUCT |
230 |
197 |
231 #ifdef COMPILER1 |
232 static java_nmethod_stats_struct c1_java_nmethod_stats; |
|
233 #endif |
|
234 #ifdef COMPILER2 |
|
235 static java_nmethod_stats_struct c2_java_nmethod_stats; |
|
236 #endif |
|
237 #if INCLUDE_JVMCI |
|
238 static java_nmethod_stats_struct jvmci_java_nmethod_stats; |
|
239 #endif |
|
240 #ifdef SHARK |
|
241 static java_nmethod_stats_struct shark_java_nmethod_stats; |
|
242 #endif |
|
243 static java_nmethod_stats_struct unknown_java_nmethod_stats; |
|
244 |
|
245 static native_nmethod_stats_struct native_nmethod_stats; |
|
246 static pc_nmethod_stats_struct pc_nmethod_stats; |
|
247 |
|
248 static void note_java_nmethod(nmethod* nm) { |
|
249 #ifdef COMPILER1 |
|
250 if (nm->is_compiled_by_c1()) { |
|
251 c1_java_nmethod_stats.note_nmethod(nm); |
|
252 } else |
|
253 #endif |
|
254 #ifdef COMPILER2 |
|
255 if (nm->is_compiled_by_c2()) { |
|
256 c2_java_nmethod_stats.note_nmethod(nm); |
|
257 } else |
|
258 #endif |
|
259 #if INCLUDE_JVMCI |
|
260 if (nm->is_compiled_by_jvmci()) { |
|
261 jvmci_java_nmethod_stats.note_nmethod(nm); |
|
262 } else |
|
263 #endif |
|
264 #ifdef SHARK |
|
265 if (nm->is_compiled_by_shark()) { |
|
266 shark_java_nmethod_stats.note_nmethod(nm); |
|
267 } else |
|
268 #endif |
|
269 { |
|
270 unknown_java_nmethod_stats.note_nmethod(nm); |
|
271 } |
|
272 } |
|
273 #endif // !PRODUCT |
|
198 |
274 |
199 //--------------------------------------------------------------------------------- |
275 //--------------------------------------------------------------------------------- |
200 |
276 |
201 |
277 |
202 ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) { |
278 ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) { |
272 //----------------------------------------------------------------------------- |
348 //----------------------------------------------------------------------------- |
273 |
349 |
274 |
350 |
275 // Helper used by both find_pc_desc methods. |
351 // Helper used by both find_pc_desc methods. |
276 static inline bool match_desc(PcDesc* pc, int pc_offset, bool approximate) { |
352 static inline bool match_desc(PcDesc* pc, int pc_offset, bool approximate) { |
277 NOT_PRODUCT(++nmethod_stats.pc_desc_tests); |
353 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_tests); |
278 if (!approximate) |
354 if (!approximate) |
279 return pc->pc_offset() == pc_offset; |
355 return pc->pc_offset() == pc_offset; |
280 else |
356 else |
281 return (pc-1)->pc_offset() < pc_offset && pc_offset <= pc->pc_offset(); |
357 return (pc-1)->pc_offset() < pc_offset && pc_offset <= pc->pc_offset(); |
282 } |
358 } |
284 void PcDescCache::reset_to(PcDesc* initial_pc_desc) { |
360 void PcDescCache::reset_to(PcDesc* initial_pc_desc) { |
285 if (initial_pc_desc == NULL) { |
361 if (initial_pc_desc == NULL) { |
286 _pc_descs[0] = NULL; // native method; no PcDescs at all |
362 _pc_descs[0] = NULL; // native method; no PcDescs at all |
287 return; |
363 return; |
288 } |
364 } |
289 NOT_PRODUCT(++nmethod_stats.pc_desc_resets); |
365 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_resets); |
290 // reset the cache by filling it with benign (non-null) values |
366 // reset the cache by filling it with benign (non-null) values |
291 assert(initial_pc_desc->pc_offset() < 0, "must be sentinel"); |
367 assert(initial_pc_desc->pc_offset() < 0, "must be sentinel"); |
292 for (int i = 0; i < cache_size; i++) |
368 for (int i = 0; i < cache_size; i++) |
293 _pc_descs[i] = initial_pc_desc; |
369 _pc_descs[i] = initial_pc_desc; |
294 } |
370 } |
295 |
371 |
296 PcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) { |
372 PcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) { |
297 NOT_PRODUCT(++nmethod_stats.pc_desc_queries); |
373 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_queries); |
298 NOT_PRODUCT(if (approximate) ++nmethod_stats.pc_desc_approx); |
374 NOT_PRODUCT(if (approximate) ++pc_nmethod_stats.pc_desc_approx); |
299 |
375 |
300 // Note: one might think that caching the most recently |
376 // Note: one might think that caching the most recently |
301 // read value separately would be a win, but one would be |
377 // read value separately would be a win, but one would be |
302 // wrong. When many threads are updating it, the cache |
378 // wrong. When many threads are updating it, the cache |
303 // line it's in would bounce between caches, negating |
379 // line it's in would bounce between caches, negating |
309 |
385 |
310 // Step one: Check the most recently added value. |
386 // Step one: Check the most recently added value. |
311 res = _pc_descs[0]; |
387 res = _pc_descs[0]; |
312 if (res == NULL) return NULL; // native method; no PcDescs at all |
388 if (res == NULL) return NULL; // native method; no PcDescs at all |
313 if (match_desc(res, pc_offset, approximate)) { |
389 if (match_desc(res, pc_offset, approximate)) { |
314 NOT_PRODUCT(++nmethod_stats.pc_desc_repeats); |
390 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_repeats); |
315 return res; |
391 return res; |
316 } |
392 } |
317 |
393 |
318 // Step two: Check the rest of the LRU cache. |
394 // Step two: Check the rest of the LRU cache. |
319 for (int i = 1; i < cache_size; ++i) { |
395 for (int i = 1; i < cache_size; ++i) { |
320 res = _pc_descs[i]; |
396 res = _pc_descs[i]; |
321 if (res->pc_offset() < 0) break; // optimization: skip empty cache |
397 if (res->pc_offset() < 0) break; // optimization: skip empty cache |
322 if (match_desc(res, pc_offset, approximate)) { |
398 if (match_desc(res, pc_offset, approximate)) { |
323 NOT_PRODUCT(++nmethod_stats.pc_desc_hits); |
399 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_hits); |
324 return res; |
400 return res; |
325 } |
401 } |
326 } |
402 } |
327 |
403 |
328 // Report failure. |
404 // Report failure. |
329 return NULL; |
405 return NULL; |
330 } |
406 } |
331 |
407 |
332 void PcDescCache::add_pc_desc(PcDesc* pc_desc) { |
408 void PcDescCache::add_pc_desc(PcDesc* pc_desc) { |
333 NOT_PRODUCT(++nmethod_stats.pc_desc_adds); |
409 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_adds); |
334 // Update the LRU cache by shifting pc_desc forward. |
410 // Update the LRU cache by shifting pc_desc forward. |
335 for (int i = 0; i < cache_size; i++) { |
411 for (int i = 0; i < cache_size; i++) { |
336 PcDesc* next = _pc_descs[i]; |
412 PcDesc* next = _pc_descs[i]; |
337 _pc_descs[i] = pc_desc; |
413 _pc_descs[i] = pc_desc; |
338 pc_desc = next; |
414 pc_desc = next; |
455 _lazy_critical_native = 0; |
531 _lazy_critical_native = 0; |
456 _has_wide_vectors = 0; |
532 _has_wide_vectors = 0; |
457 _marked_for_deoptimization = 0; |
533 _marked_for_deoptimization = 0; |
458 _lock_count = 0; |
534 _lock_count = 0; |
459 _stack_traversal_mark = 0; |
535 _stack_traversal_mark = 0; |
460 _unload_reported = false; // jvmti state |
536 _unload_reported = false; // jvmti state |
461 |
537 |
462 #ifdef ASSERT |
538 #ifdef ASSERT |
463 _oops_are_stale = false; |
539 _oops_are_stale = false; |
464 #endif |
540 #endif |
465 |
541 |
473 } |
549 } |
474 _scavenge_root_state = 0; |
550 _scavenge_root_state = 0; |
475 _compiler = NULL; |
551 _compiler = NULL; |
476 #if INCLUDE_RTM_OPT |
552 #if INCLUDE_RTM_OPT |
477 _rtm_state = NoRTM; |
553 _rtm_state = NoRTM; |
554 #endif |
|
555 #if INCLUDE_JVMCI |
|
556 _jvmci_installed_code = NULL; |
|
557 _speculation_log = NULL; |
|
478 #endif |
558 #endif |
479 } |
559 } |
480 |
560 |
481 nmethod* nmethod::new_native_nmethod(methodHandle method, |
561 nmethod* nmethod::new_native_nmethod(methodHandle method, |
482 int compile_id, |
562 int compile_id, |
499 nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), native_nmethod_size, |
579 nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), native_nmethod_size, |
500 compile_id, &offsets, |
580 compile_id, &offsets, |
501 code_buffer, frame_size, |
581 code_buffer, frame_size, |
502 basic_lock_owner_sp_offset, |
582 basic_lock_owner_sp_offset, |
503 basic_lock_sp_offset, oop_maps); |
583 basic_lock_sp_offset, oop_maps); |
504 NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_native_nmethod(nm)); |
584 NOT_PRODUCT(if (nm != NULL) native_nmethod_stats.note_native_nmethod(nm)); |
505 if ((PrintAssembly || CompilerOracle::should_print(method)) && nm != NULL) { |
585 if ((PrintAssembly || CompilerOracle::should_print(method)) && nm != NULL) { |
506 Disassembler::decode(nm); |
586 Disassembler::decode(nm); |
507 } |
587 } |
508 } |
588 } |
509 // verify nmethod |
589 // verify nmethod |
527 OopMapSet* oop_maps, |
607 OopMapSet* oop_maps, |
528 ExceptionHandlerTable* handler_table, |
608 ExceptionHandlerTable* handler_table, |
529 ImplicitExceptionTable* nul_chk_table, |
609 ImplicitExceptionTable* nul_chk_table, |
530 AbstractCompiler* compiler, |
610 AbstractCompiler* compiler, |
531 int comp_level |
611 int comp_level |
612 #if INCLUDE_JVMCI |
|
613 , Handle installed_code, |
|
614 Handle speculationLog |
|
615 #endif |
|
532 ) |
616 ) |
533 { |
617 { |
534 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); |
618 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); |
535 code_buffer->finalize_oop_references(method); |
619 code_buffer->finalize_oop_references(method); |
536 // create nmethod |
620 // create nmethod |
549 orig_pc_offset, debug_info, dependencies, code_buffer, frame_size, |
633 orig_pc_offset, debug_info, dependencies, code_buffer, frame_size, |
550 oop_maps, |
634 oop_maps, |
551 handler_table, |
635 handler_table, |
552 nul_chk_table, |
636 nul_chk_table, |
553 compiler, |
637 compiler, |
554 comp_level); |
638 comp_level |
639 #if INCLUDE_JVMCI |
|
640 , installed_code, |
|
641 speculationLog |
|
642 #endif |
|
643 ); |
|
555 |
644 |
556 if (nm != NULL) { |
645 if (nm != NULL) { |
557 // To make dependency checking during class loading fast, record |
646 // To make dependency checking during class loading fast, record |
558 // the nmethod dependencies in the classes it is dependent on. |
647 // the nmethod dependencies in the classes it is dependent on. |
559 // This allows the dependency checking code to simply walk the |
648 // This allows the dependency checking code to simply walk the |
574 } |
663 } |
575 // record this nmethod as dependent on this klass |
664 // record this nmethod as dependent on this klass |
576 InstanceKlass::cast(klass)->add_dependent_nmethod(nm); |
665 InstanceKlass::cast(klass)->add_dependent_nmethod(nm); |
577 } |
666 } |
578 } |
667 } |
579 NOT_PRODUCT(nmethod_stats.note_nmethod(nm)); |
668 NOT_PRODUCT(if (nm != NULL) note_java_nmethod(nm)); |
580 if (PrintAssembly || CompilerOracle::has_option_string(method, "PrintAssembly")) { |
669 if (PrintAssembly || CompilerOracle::has_option_string(method, "PrintAssembly")) { |
581 Disassembler::decode(nm); |
670 Disassembler::decode(nm); |
582 } |
671 } |
583 } |
672 } |
584 } |
673 } |
589 nm->log_new_nmethod(); |
678 nm->log_new_nmethod(); |
590 } |
679 } |
591 return nm; |
680 return nm; |
592 } |
681 } |
593 |
682 |
594 |
683 #ifdef _MSC_VER |
684 #pragma warning(push) |
|
685 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list |
|
686 #endif |
|
595 // For native wrappers |
687 // For native wrappers |
596 nmethod::nmethod( |
688 nmethod::nmethod( |
597 Method* method, |
689 Method* method, |
598 int nmethod_size, |
690 int nmethod_size, |
599 int compile_id, |
691 int compile_id, |
679 xtty->tail("print_native_nmethod"); |
771 xtty->tail("print_native_nmethod"); |
680 } |
772 } |
681 } |
773 } |
682 } |
774 } |
683 |
775 |
776 #ifdef _MSC_VER |
|
777 #pragma warning(pop) |
|
778 #endif |
|
779 |
|
684 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () { |
780 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () { |
685 return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level)); |
781 return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level)); |
686 } |
782 } |
687 |
783 |
688 nmethod::nmethod( |
784 nmethod::nmethod( |
699 OopMapSet* oop_maps, |
795 OopMapSet* oop_maps, |
700 ExceptionHandlerTable* handler_table, |
796 ExceptionHandlerTable* handler_table, |
701 ImplicitExceptionTable* nul_chk_table, |
797 ImplicitExceptionTable* nul_chk_table, |
702 AbstractCompiler* compiler, |
798 AbstractCompiler* compiler, |
703 int comp_level |
799 int comp_level |
800 #if INCLUDE_JVMCI |
|
801 , Handle installed_code, |
|
802 Handle speculation_log |
|
803 #endif |
|
704 ) |
804 ) |
705 : CodeBlob("nmethod", code_buffer, sizeof(nmethod), |
805 : CodeBlob("nmethod", code_buffer, sizeof(nmethod), |
706 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps), |
806 nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps), |
707 _native_receiver_sp_offset(in_ByteSize(-1)), |
807 _native_receiver_sp_offset(in_ByteSize(-1)), |
708 _native_basic_lock_sp_offset(in_ByteSize(-1)) |
808 _native_basic_lock_sp_offset(in_ByteSize(-1)) |
723 |
823 |
724 // Section offsets |
824 // Section offsets |
725 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); |
825 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); |
726 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); |
826 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); |
727 |
827 |
828 #if INCLUDE_JVMCI |
|
829 _jvmci_installed_code = installed_code(); |
|
830 _speculation_log = (instanceOop)speculation_log(); |
|
831 |
|
832 if (compiler->is_jvmci()) { |
|
833 // JVMCI might not produce any stub sections |
|
834 if (offsets->value(CodeOffsets::Exceptions) != -1) { |
|
835 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions); |
|
836 } else { |
|
837 _exception_offset = -1; |
|
838 } |
|
839 if (offsets->value(CodeOffsets::Deopt) != -1) { |
|
840 _deoptimize_offset = code_offset() + offsets->value(CodeOffsets::Deopt); |
|
841 } else { |
|
842 _deoptimize_offset = -1; |
|
843 } |
|
844 if (offsets->value(CodeOffsets::DeoptMH) != -1) { |
|
845 _deoptimize_mh_offset = code_offset() + offsets->value(CodeOffsets::DeoptMH); |
|
846 } else { |
|
847 _deoptimize_mh_offset = -1; |
|
848 } |
|
849 } else { |
|
850 #endif |
|
728 // Exception handler and deopt handler are in the stub section |
851 // Exception handler and deopt handler are in the stub section |
729 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set"); |
852 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set"); |
730 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set"); |
853 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set"); |
854 |
|
731 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions); |
855 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions); |
732 _deoptimize_offset = _stub_offset + offsets->value(CodeOffsets::Deopt); |
856 _deoptimize_offset = _stub_offset + offsets->value(CodeOffsets::Deopt); |
733 if (offsets->value(CodeOffsets::DeoptMH) != -1) { |
857 if (offsets->value(CodeOffsets::DeoptMH) != -1) { |
734 _deoptimize_mh_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH); |
858 _deoptimize_mh_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH); |
735 } else { |
859 } else { |
736 _deoptimize_mh_offset = -1; |
860 _deoptimize_mh_offset = -1; |
861 #if INCLUDE_JVMCI |
|
862 } |
|
863 #endif |
|
737 } |
864 } |
738 if (offsets->value(CodeOffsets::UnwindHandler) != -1) { |
865 if (offsets->value(CodeOffsets::UnwindHandler) != -1) { |
739 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler); |
866 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler); |
740 } else { |
867 } else { |
741 _unwind_handler_offset = -1; |
868 _unwind_handler_offset = -1; |
775 handler_table->copy_to(this); |
902 handler_table->copy_to(this); |
776 nul_chk_table->copy_to(this); |
903 nul_chk_table->copy_to(this); |
777 |
904 |
778 // we use the information of entry points to find out if a method is |
905 // we use the information of entry points to find out if a method is |
779 // static or non static |
906 // static or non static |
780 assert(compiler->is_c2() || |
907 assert(compiler->is_c2() || compiler->is_jvmci() || |
781 _method->is_static() == (entry_point() == _verified_entry_point), |
908 _method->is_static() == (entry_point() == _verified_entry_point), |
782 " entry points must be same for static methods and vice versa"); |
909 " entry points must be same for static methods and vice versa"); |
783 } |
910 } |
784 |
911 |
785 bool printnmethods = PrintNMethods |
912 bool printnmethods = PrintNMethods || PrintNMethodsAtLevel == _comp_level |
786 || CompilerOracle::should_print(_method) |
913 || CompilerOracle::should_print(_method) |
787 || CompilerOracle::has_option_string(_method, "PrintNMethods"); |
914 || CompilerOracle::has_option_string(_method, "PrintNMethods"); |
788 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) { |
915 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) { |
789 print_nmethod(printnmethods); |
916 print_nmethod(printnmethods); |
790 } |
917 } |
791 } |
918 } |
792 |
|
793 |
919 |
794 // Print a short set of xml attributes to identify this nmethod. The |
920 // Print a short set of xml attributes to identify this nmethod. The |
795 // output should be embedded in some other element. |
921 // output should be embedded in some other element. |
796 void nmethod::log_identity(xmlStream* log) const { |
922 void nmethod::log_identity(xmlStream* log) const { |
797 log->print(" compile_id='%d'", compile_id()); |
923 log->print(" compile_id='%d'", compile_id()); |
829 LOG_OFFSET(xtty, scopes_pcs); |
955 LOG_OFFSET(xtty, scopes_pcs); |
830 LOG_OFFSET(xtty, dependencies); |
956 LOG_OFFSET(xtty, dependencies); |
831 LOG_OFFSET(xtty, handler_table); |
957 LOG_OFFSET(xtty, handler_table); |
832 LOG_OFFSET(xtty, nul_chk_table); |
958 LOG_OFFSET(xtty, nul_chk_table); |
833 LOG_OFFSET(xtty, oops); |
959 LOG_OFFSET(xtty, oops); |
960 LOG_OFFSET(xtty, metadata); |
|
834 |
961 |
835 xtty->method(method()); |
962 xtty->method(method()); |
836 xtty->stamp(); |
963 xtty->stamp(); |
837 xtty->end_elem(); |
964 xtty->end_elem(); |
838 } |
965 } |
870 print_pcs(); |
997 print_pcs(); |
871 if (oop_maps()) { |
998 if (oop_maps()) { |
872 oop_maps()->print(); |
999 oop_maps()->print(); |
873 } |
1000 } |
874 } |
1001 } |
875 if (PrintDebugInfo) { |
1002 if (PrintDebugInfo || CompilerOracle::has_option_string(_method, "PrintDebugInfo")) { |
876 print_scopes(); |
1003 print_scopes(); |
877 } |
1004 } |
878 if (PrintRelocations) { |
1005 if (PrintRelocations || CompilerOracle::has_option_string(_method, "PrintRelocations")) { |
879 print_relocations(); |
1006 print_relocations(); |
880 } |
1007 } |
881 if (PrintDependencies) { |
1008 if (PrintDependencies || CompilerOracle::has_option_string(_method, "PrintDependencies")) { |
882 print_dependencies(); |
1009 print_dependencies(); |
883 } |
1010 } |
884 if (PrintExceptionHandlers) { |
1011 if (PrintExceptionHandlers) { |
885 print_handler_table(); |
1012 print_handler_table(); |
886 print_nul_chk_table(); |
1013 print_nul_chk_table(); |
986 |
1113 |
987 ScopeDesc* nmethod::scope_desc_at(address pc) { |
1114 ScopeDesc* nmethod::scope_desc_at(address pc) { |
988 PcDesc* pd = pc_desc_at(pc); |
1115 PcDesc* pd = pc_desc_at(pc); |
989 guarantee(pd != NULL, "scope must be present"); |
1116 guarantee(pd != NULL, "scope must be present"); |
990 return new ScopeDesc(this, pd->scope_decode_offset(), |
1117 return new ScopeDesc(this, pd->scope_decode_offset(), |
991 pd->obj_decode_offset(), pd->should_reexecute(), |
1118 pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), |
992 pd->return_oop()); |
1119 pd->return_oop()); |
993 } |
1120 } |
994 |
1121 |
995 |
1122 |
996 void nmethod::clear_inline_caches() { |
1123 void nmethod::clear_inline_caches() { |
1157 return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() && |
1284 return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() && |
1158 !is_locked_by_vm(); |
1285 !is_locked_by_vm(); |
1159 } |
1286 } |
1160 |
1287 |
1161 void nmethod::inc_decompile_count() { |
1288 void nmethod::inc_decompile_count() { |
1162 if (!is_compiled_by_c2()) return; |
1289 if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return; |
1163 // Could be gated by ProfileTraps, but do not bother... |
1290 // Could be gated by ProfileTraps, but do not bother... |
1164 Method* m = method(); |
1291 Method* m = method(); |
1165 if (m == NULL) return; |
1292 if (m == NULL) return; |
1166 MethodData* mdo = m->method_data(); |
1293 MethodData* mdo = m->method_data(); |
1167 if (mdo == NULL) return; |
1294 if (mdo == NULL) return; |
1221 if (_method->code() == this) { |
1348 if (_method->code() == this) { |
1222 _method->clear_code(); // Break a cycle |
1349 _method->clear_code(); // Break a cycle |
1223 } |
1350 } |
1224 _method = NULL; // Clear the method of this dead nmethod |
1351 _method = NULL; // Clear the method of this dead nmethod |
1225 } |
1352 } |
1353 |
|
1226 // Make the class unloaded - i.e., change state and notify sweeper |
1354 // Make the class unloaded - i.e., change state and notify sweeper |
1227 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
1355 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
1228 if (is_in_use()) { |
1356 if (is_in_use()) { |
1229 // Transitioning directly from live to unloaded -- so |
1357 // Transitioning directly from live to unloaded -- so |
1230 // we need to force a cache clean-up; remember this |
1358 // we need to force a cache clean-up; remember this |
1232 CodeCache::set_needs_cache_clean(true); |
1360 CodeCache::set_needs_cache_clean(true); |
1233 } |
1361 } |
1234 |
1362 |
1235 // Unregister must be done before the state change |
1363 // Unregister must be done before the state change |
1236 Universe::heap()->unregister_nmethod(this); |
1364 Universe::heap()->unregister_nmethod(this); |
1365 |
|
1366 #if INCLUDE_JVMCI |
|
1367 // The method can only be unloaded after the pointer to the installed code |
|
1368 // Java wrapper is no longer alive. Here we need to clear out this weak |
|
1369 // reference to the dead object. Nulling out the reference has to happen |
|
1370 // after the method is unregistered since the original value may be still |
|
1371 // tracked by the rset. |
|
1372 if (_jvmci_installed_code != NULL) { |
|
1373 InstalledCode::set_address(_jvmci_installed_code, 0); |
|
1374 _jvmci_installed_code = NULL; |
|
1375 } |
|
1376 #endif |
|
1237 |
1377 |
1238 _state = unloaded; |
1378 _state = unloaded; |
1239 |
1379 |
1240 // Log the unloading. |
1380 // Log the unloading. |
1241 log_state_change(); |
1381 log_state_change(); |
1396 // nmethod is in zombie state |
1536 // nmethod is in zombie state |
1397 set_method(NULL); |
1537 set_method(NULL); |
1398 } else { |
1538 } else { |
1399 assert(state == not_entrant, "other cases may need to be handled differently"); |
1539 assert(state == not_entrant, "other cases may need to be handled differently"); |
1400 } |
1540 } |
1541 #if INCLUDE_JVMCI |
|
1542 if (_jvmci_installed_code != NULL) { |
|
1543 // Break the link between nmethod and InstalledCode such that the nmethod can subsequently be flushed safely. |
|
1544 InstalledCode::set_address(_jvmci_installed_code, 0); |
|
1545 } |
|
1546 #endif |
|
1401 |
1547 |
1402 if (TraceCreateZombies) { |
1548 if (TraceCreateZombies) { |
1403 tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", |
1549 ResourceMark m; |
1404 p2i(this), (state == not_entrant) ? "not entrant" : "zombie"); |
1550 tty->print_cr("nmethod <" INTPTR_FORMAT "> %s code made %s", p2i(this), this->method() ? this->method()->name_and_sig_as_C_string() : "null", (state == not_entrant) ? "not entrant" : "zombie"); |
1405 } |
1551 } |
1406 |
1552 |
1407 NMethodSweeper::report_state_change(this); |
1553 NMethodSweeper::report_state_change(this); |
1408 return true; |
1554 return true; |
1409 } |
1555 } |
1689 if (can_unload(is_alive, p, unloading_occurred)) { |
1835 if (can_unload(is_alive, p, unloading_occurred)) { |
1690 return; |
1836 return; |
1691 } |
1837 } |
1692 } |
1838 } |
1693 |
1839 |
1840 #if INCLUDE_JVMCI |
|
1841 // Follow JVMCI method |
|
1842 BarrierSet* bs = Universe::heap()->barrier_set(); |
|
1843 if (_jvmci_installed_code != NULL) { |
|
1844 if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) { |
|
1845 if (!is_alive->do_object_b(_jvmci_installed_code)) { |
|
1846 bs->write_ref_nmethod_pre(&_jvmci_installed_code, this); |
|
1847 _jvmci_installed_code = NULL; |
|
1848 bs->write_ref_nmethod_post(&_jvmci_installed_code, this); |
|
1849 } |
|
1850 } else { |
|
1851 if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) { |
|
1852 return; |
|
1853 } |
|
1854 } |
|
1855 } |
|
1856 |
|
1857 if (_speculation_log != NULL) { |
|
1858 if (!is_alive->do_object_b(_speculation_log)) { |
|
1859 bs->write_ref_nmethod_pre(&_speculation_log, this); |
|
1860 _speculation_log = NULL; |
|
1861 bs->write_ref_nmethod_post(&_speculation_log, this); |
|
1862 } |
|
1863 } |
|
1864 #endif |
|
1865 |
|
1866 |
|
1694 // Ensure that all metadata is still alive |
1867 // Ensure that all metadata is still alive |
1695 verify_metadata_loaders(low_boundary, is_alive); |
1868 verify_metadata_loaders(low_boundary, is_alive); |
1696 } |
1869 } |
1697 |
1870 |
1698 template <class CompiledICorStaticCall> |
1871 template <class CompiledICorStaticCall> |
1771 // call to post_compiled_method_unload() so that the unloading |
1944 // call to post_compiled_method_unload() so that the unloading |
1772 // of this nmethod is reported. |
1945 // of this nmethod is reported. |
1773 unloading_occurred = true; |
1946 unloading_occurred = true; |
1774 } |
1947 } |
1775 |
1948 |
1949 #if INCLUDE_JVMCI |
|
1950 // Follow JVMCI method |
|
1951 if (_jvmci_installed_code != NULL) { |
|
1952 if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) { |
|
1953 if (!is_alive->do_object_b(_jvmci_installed_code)) { |
|
1954 _jvmci_installed_code = NULL; |
|
1955 } |
|
1956 } else { |
|
1957 if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) { |
|
1958 return false; |
|
1959 } |
|
1960 } |
|
1961 } |
|
1962 |
|
1963 if (_speculation_log != NULL) { |
|
1964 if (!is_alive->do_object_b(_speculation_log)) { |
|
1965 _speculation_log = NULL; |
|
1966 } |
|
1967 } |
|
1968 #endif |
|
1969 |
|
1776 // Exception cache |
1970 // Exception cache |
1777 clean_exception_cache(is_alive); |
1971 clean_exception_cache(is_alive); |
1778 |
1972 |
1779 bool is_unloaded = false; |
1973 bool is_unloaded = false; |
1780 bool postponed = false; |
1974 bool postponed = false; |
1827 } |
2021 } |
1828 |
2022 |
1829 if (is_unloaded) { |
2023 if (is_unloaded) { |
1830 return postponed; |
2024 return postponed; |
1831 } |
2025 } |
2026 |
|
2027 #if INCLUDE_JVMCI |
|
2028 // Follow JVMCI method |
|
2029 BarrierSet* bs = Universe::heap()->barrier_set(); |
|
2030 if (_jvmci_installed_code != NULL) { |
|
2031 if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) { |
|
2032 if (!is_alive->do_object_b(_jvmci_installed_code)) { |
|
2033 bs->write_ref_nmethod_pre(&_jvmci_installed_code, this); |
|
2034 _jvmci_installed_code = NULL; |
|
2035 bs->write_ref_nmethod_post(&_jvmci_installed_code, this); |
|
2036 } |
|
2037 } else { |
|
2038 if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) { |
|
2039 is_unloaded = true; |
|
2040 } |
|
2041 } |
|
2042 } |
|
2043 |
|
2044 if (_speculation_log != NULL) { |
|
2045 if (!is_alive->do_object_b(_speculation_log)) { |
|
2046 bs->write_ref_nmethod_pre(&_speculation_log, this); |
|
2047 _speculation_log = NULL; |
|
2048 bs->write_ref_nmethod_post(&_speculation_log, this); |
|
2049 } |
|
2050 } |
|
2051 #endif |
|
1832 |
2052 |
1833 // Ensure that all metadata is still alive |
2053 // Ensure that all metadata is still alive |
1834 verify_metadata_loaders(low_boundary, is_alive); |
2054 verify_metadata_loaders(low_boundary, is_alive); |
1835 |
2055 |
1836 return postponed; |
2056 return postponed; |
2012 low_boundary += NativeJump::instruction_size; |
2232 low_boundary += NativeJump::instruction_size; |
2013 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. |
2233 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. |
2014 // (See comment above.) |
2234 // (See comment above.) |
2015 } |
2235 } |
2016 |
2236 |
2237 #if INCLUDE_JVMCI |
|
2238 if (_jvmci_installed_code != NULL) { |
|
2239 f->do_oop((oop*) &_jvmci_installed_code); |
|
2240 } |
|
2241 if (_speculation_log != NULL) { |
|
2242 f->do_oop((oop*) &_speculation_log); |
|
2243 } |
|
2244 #endif |
|
2245 |
|
2017 RelocIterator iter(this, low_boundary); |
2246 RelocIterator iter(this, low_boundary); |
2018 |
2247 |
2019 while (iter.next()) { |
2248 while (iter.next()) { |
2020 if (iter.type() == relocInfo::oop_type ) { |
2249 if (iter.type() == relocInfo::oop_type ) { |
2021 oop_Relocation* r = iter.oop_reloc(); |
2250 oop_Relocation* r = iter.oop_reloc(); |
2136 |
2365 |
2137 // Method that knows how to preserve outgoing arguments at call. This method must be |
2366 // Method that knows how to preserve outgoing arguments at call. This method must be |
2138 // called with a frame corresponding to a Java invoke |
2367 // called with a frame corresponding to a Java invoke |
2139 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { |
2368 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { |
2140 #ifndef SHARK |
2369 #ifndef SHARK |
2141 if (!method()->is_native()) { |
2370 if (method() != NULL && !method()->is_native()) { |
2142 SimpleScopeDesc ssd(this, fr.pc()); |
2371 SimpleScopeDesc ssd(this, fr.pc()); |
2143 Bytecode_invoke call(ssd.method(), ssd.bci()); |
2372 Bytecode_invoke call(ssd.method(), ssd.bci()); |
2144 bool has_receiver = call.has_receiver(); |
2373 bool has_receiver = call.has_receiver(); |
2145 bool has_appendix = call.has_appendix(); |
2374 bool has_appendix = call.has_appendix(); |
2146 Symbol* signature = call.signature(); |
2375 Symbol* signature = call.signature(); |
2202 void nmethod::copy_scopes_data(u_char* buffer, int size) { |
2431 void nmethod::copy_scopes_data(u_char* buffer, int size) { |
2203 assert(scopes_data_size() >= size, "oob"); |
2432 assert(scopes_data_size() >= size, "oob"); |
2204 memcpy(scopes_data_begin(), buffer, size); |
2433 memcpy(scopes_data_begin(), buffer, size); |
2205 } |
2434 } |
2206 |
2435 |
2436 // When using JVMCI the address might be off by the size of a call instruction. |
|
2437 bool nmethod::is_deopt_entry(address pc) { |
|
2438 return pc == deopt_handler_begin() |
|
2439 #if INCLUDE_JVMCI |
|
2440 || pc == (deopt_handler_begin() + NativeCall::instruction_size) |
|
2441 #endif |
|
2442 ; |
|
2443 } |
|
2207 |
2444 |
2208 #ifdef ASSERT |
2445 #ifdef ASSERT |
2209 static PcDesc* linear_search(nmethod* nm, int pc_offset, bool approximate) { |
2446 static PcDesc* linear_search(nmethod* nm, int pc_offset, bool approximate) { |
2210 PcDesc* lower = nm->scopes_pcs_begin(); |
2447 PcDesc* lower = nm->scopes_pcs_begin(); |
2211 PcDesc* upper = nm->scopes_pcs_end(); |
2448 PcDesc* upper = nm->scopes_pcs_end(); |
2212 lower += 1; // exclude initial sentinel |
2449 lower += 1; // exclude initial sentinel |
2213 PcDesc* res = NULL; |
2450 PcDesc* res = NULL; |
2214 for (PcDesc* p = lower; p < upper; p++) { |
2451 for (PcDesc* p = lower; p < upper; p++) { |
2215 NOT_PRODUCT(--nmethod_stats.pc_desc_tests); // don't count this call to match_desc |
2452 NOT_PRODUCT(--pc_nmethod_stats.pc_desc_tests); // don't count this call to match_desc |
2216 if (match_desc(p, pc_offset, approximate)) { |
2453 if (match_desc(p, pc_offset, approximate)) { |
2217 if (res == NULL) |
2454 if (res == NULL) |
2218 res = p; |
2455 res = p; |
2219 else |
2456 else |
2220 res = (PcDesc*) badAddress; |
2457 res = (PcDesc*) badAddress; |
2257 assert(upper->pc_offset() >= pc_offset, "sanity") |
2494 assert(upper->pc_offset() >= pc_offset, "sanity") |
2258 assert_LU_OK; |
2495 assert_LU_OK; |
2259 |
2496 |
2260 // Use the last successful return as a split point. |
2497 // Use the last successful return as a split point. |
2261 PcDesc* mid = _pc_desc_cache.last_pc_desc(); |
2498 PcDesc* mid = _pc_desc_cache.last_pc_desc(); |
2262 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); |
2499 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_searches); |
2263 if (mid->pc_offset() < pc_offset) { |
2500 if (mid->pc_offset() < pc_offset) { |
2264 lower = mid; |
2501 lower = mid; |
2265 } else { |
2502 } else { |
2266 upper = mid; |
2503 upper = mid; |
2267 } |
2504 } |
2270 const int LOG2_RADIX = 4 /*smaller steps in debug mode:*/ debug_only(-1); |
2507 const int LOG2_RADIX = 4 /*smaller steps in debug mode:*/ debug_only(-1); |
2271 const int RADIX = (1 << LOG2_RADIX); |
2508 const int RADIX = (1 << LOG2_RADIX); |
2272 for (int step = (1 << (LOG2_RADIX*3)); step > 1; step >>= LOG2_RADIX) { |
2509 for (int step = (1 << (LOG2_RADIX*3)); step > 1; step >>= LOG2_RADIX) { |
2273 while ((mid = lower + step) < upper) { |
2510 while ((mid = lower + step) < upper) { |
2274 assert_LU_OK; |
2511 assert_LU_OK; |
2275 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); |
2512 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_searches); |
2276 if (mid->pc_offset() < pc_offset) { |
2513 if (mid->pc_offset() < pc_offset) { |
2277 lower = mid; |
2514 lower = mid; |
2278 } else { |
2515 } else { |
2279 upper = mid; |
2516 upper = mid; |
2280 break; |
2517 break; |
2285 |
2522 |
2286 // Sneak up on the value with a linear search of length ~16. |
2523 // Sneak up on the value with a linear search of length ~16. |
2287 while (true) { |
2524 while (true) { |
2288 assert_LU_OK; |
2525 assert_LU_OK; |
2289 mid = lower + 1; |
2526 mid = lower + 1; |
2290 NOT_PRODUCT(++nmethod_stats.pc_desc_searches); |
2527 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_searches); |
2291 if (mid->pc_offset() < pc_offset) { |
2528 if (mid->pc_offset() < pc_offset) { |
2292 lower = mid; |
2529 lower = mid; |
2293 } else { |
2530 } else { |
2294 upper = mid; |
2531 upper = mid; |
2295 break; |
2532 break; |
2472 if (nm == NULL) return; |
2709 if (nm == NULL) return; |
2473 Atomic::dec(&nm->_lock_count); |
2710 Atomic::dec(&nm->_lock_count); |
2474 assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock"); |
2711 assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock"); |
2475 } |
2712 } |
2476 |
2713 |
2477 |
|
2478 // ----------------------------------------------------------------------------- |
2714 // ----------------------------------------------------------------------------- |
2479 // nmethod::get_deopt_original_pc |
2715 // nmethod::get_deopt_original_pc |
2480 // |
2716 // |
2481 // Return the original PC for the given PC if: |
2717 // Return the original PC for the given PC if: |
2482 // (a) the given PC belongs to a nmethod and |
2718 // (a) the given PC belongs to a nmethod and |
2585 } |
2821 } |
2586 |
2822 |
2587 PcDesc* pd = pc_desc_at(nativeCall_at(call_site)->return_address()); |
2823 PcDesc* pd = pc_desc_at(nativeCall_at(call_site)->return_address()); |
2588 assert(pd != NULL, "PcDesc must exist"); |
2824 assert(pd != NULL, "PcDesc must exist"); |
2589 for (ScopeDesc* sd = new ScopeDesc(this, pd->scope_decode_offset(), |
2825 for (ScopeDesc* sd = new ScopeDesc(this, pd->scope_decode_offset(), |
2590 pd->obj_decode_offset(), pd->should_reexecute(), |
2826 pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), |
2591 pd->return_oop()); |
2827 pd->return_oop()); |
2592 !sd->is_top(); sd = sd->sender()) { |
2828 !sd->is_top(); sd = sd->sender()) { |
2593 sd->verify(); |
2829 sd->verify(); |
2594 } |
2830 } |
2595 } |
2831 } |
2678 tty->print("(c1) "); |
2914 tty->print("(c1) "); |
2679 } else if (is_compiled_by_c2()) { |
2915 } else if (is_compiled_by_c2()) { |
2680 tty->print("(c2) "); |
2916 tty->print("(c2) "); |
2681 } else if (is_compiled_by_shark()) { |
2917 } else if (is_compiled_by_shark()) { |
2682 tty->print("(shark) "); |
2918 tty->print("(shark) "); |
2919 } else if (is_compiled_by_jvmci()) { |
|
2920 tty->print("(JVMCI) "); |
|
2683 } else { |
2921 } else { |
2684 tty->print("(nm) "); |
2922 tty->print("(nm) "); |
2685 } |
2923 } |
2686 |
2924 |
2687 print_on(tty, NULL); |
2925 print_on(tty, NULL); |
2762 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { |
3000 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { |
2763 if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null) |
3001 if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null) |
2764 continue; |
3002 continue; |
2765 |
3003 |
2766 ScopeDesc* sd = scope_desc_at(p->real_pc(this)); |
3004 ScopeDesc* sd = scope_desc_at(p->real_pc(this)); |
2767 sd->print_on(tty, p); |
3005 while (sd != NULL) { |
3006 sd->print_on(tty, p); |
|
3007 sd = sd->sender(); |
|
3008 } |
|
2768 } |
3009 } |
2769 } |
3010 } |
2770 |
3011 |
2771 void nmethod::print_dependencies() { |
3012 void nmethod::print_dependencies() { |
2772 ResourceMark rm; |
3013 ResourceMark rm; |
2879 // Return a the last scope in (begin..end] |
3120 // Return a the last scope in (begin..end] |
2880 ScopeDesc* nmethod::scope_desc_in(address begin, address end) { |
3121 ScopeDesc* nmethod::scope_desc_in(address begin, address end) { |
2881 PcDesc* p = pc_desc_near(begin+1); |
3122 PcDesc* p = pc_desc_near(begin+1); |
2882 if (p != NULL && p->real_pc(this) <= end) { |
3123 if (p != NULL && p->real_pc(this) <= end) { |
2883 return new ScopeDesc(this, p->scope_decode_offset(), |
3124 return new ScopeDesc(this, p->scope_decode_offset(), |
2884 p->obj_decode_offset(), p->should_reexecute(), |
3125 p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(), |
2885 p->return_oop()); |
3126 p->return_oop()); |
2886 } |
3127 } |
2887 return NULL; |
3128 return NULL; |
2888 } |
3129 } |
2889 |
3130 |
2890 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin) const { |
3131 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin) const { |
2891 if (block_begin == entry_point()) stream->print_cr("[Entry Point]"); |
3132 if (block_begin == entry_point()) stream->print_cr("[Entry Point]"); |
2892 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]"); |
3133 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]"); |
2893 if (block_begin == exception_begin()) stream->print_cr("[Exception Handler]"); |
3134 if (JVMCI_ONLY(_exception_offset >= 0 &&) block_begin == exception_begin()) stream->print_cr("[Exception Handler]"); |
2894 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]"); |
3135 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]"); |
2895 if (block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]"); |
3136 if (JVMCI_ONLY(_deoptimize_offset >= 0 &&) block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]"); |
2896 |
3137 |
2897 if (has_method_handle_invokes()) |
3138 if (has_method_handle_invokes()) |
2898 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]"); |
3139 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]"); |
2899 |
3140 |
2900 if (block_begin == consts_begin()) stream->print_cr("[Constants]"); |
3141 if (block_begin == consts_begin()) stream->print_cr("[Constants]"); |
3056 else |
3297 else |
3057 st->print("<UNKNOWN>"); |
3298 st->print("<UNKNOWN>"); |
3058 } |
3299 } |
3059 } |
3300 } |
3060 } |
3301 } |
3302 st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop()); |
|
3061 } |
3303 } |
3062 |
3304 |
3063 // Print all scopes |
3305 // Print all scopes |
3064 for (;sd != NULL; sd = sd->sender()) { |
3306 for (;sd != NULL; sd = sd->sender()) { |
3065 st->move_to(column); |
3307 st->move_to(column); |
3128 } |
3370 } |
3129 |
3371 |
3130 void nmethod::print_statistics() { |
3372 void nmethod::print_statistics() { |
3131 ttyLocker ttyl; |
3373 ttyLocker ttyl; |
3132 if (xtty != NULL) xtty->head("statistics type='nmethod'"); |
3374 if (xtty != NULL) xtty->head("statistics type='nmethod'"); |
3133 nmethod_stats.print_native_nmethod_stats(); |
3375 native_nmethod_stats.print_native_nmethod_stats(); |
3134 nmethod_stats.print_nmethod_stats(); |
3376 #ifdef COMPILER1 |
3377 c1_java_nmethod_stats.print_nmethod_stats("C1"); |
|
3378 #endif |
|
3379 #ifdef COMPILER2 |
|
3380 c2_java_nmethod_stats.print_nmethod_stats("C2"); |
|
3381 #endif |
|
3382 #if INCLUDE_JVMCI |
|
3383 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI"); |
|
3384 #endif |
|
3385 #ifdef SHARK |
|
3386 shark_java_nmethod_stats.print_nmethod_stats("Shark"); |
|
3387 #endif |
|
3388 unknown_java_nmethod_stats.print_nmethod_stats("Unknown"); |
|
3135 DebugInformationRecorder::print_statistics(); |
3389 DebugInformationRecorder::print_statistics(); |
3136 nmethod_stats.print_pc_stats(); |
3390 #ifndef PRODUCT |
3391 pc_nmethod_stats.print_pc_stats(); |
|
3392 #endif |
|
3137 Dependencies::print_statistics(); |
3393 Dependencies::print_statistics(); |
3138 if (xtty != NULL) xtty->tail("statistics"); |
3394 if (xtty != NULL) xtty->tail("statistics"); |
3139 } |
3395 } |
3140 |
3396 |
3141 #endif // PRODUCT |
3397 #endif // !PRODUCT |
3398 |
|
3399 #if INCLUDE_JVMCI |
|
3400 char* nmethod::jvmci_installed_code_name(char* buf, size_t buflen) { |
|
3401 if (!this->is_compiled_by_jvmci()) { |
|
3402 return NULL; |
|
3403 } |
|
3404 oop installedCode = this->jvmci_installed_code(); |
|
3405 if (installedCode != NULL) { |
|
3406 oop installedCodeName = NULL; |
|
3407 if (installedCode->is_a(InstalledCode::klass())) { |
|
3408 installedCodeName = InstalledCode::name(installedCode); |
|
3409 } |
|
3410 if (installedCodeName != NULL) { |
|
3411 return java_lang_String::as_utf8_string(installedCodeName, buf, (int)buflen); |
|
3412 } else { |
|
3413 jio_snprintf(buf, buflen, "null"); |
|
3414 return buf; |
|
3415 } |
|
3416 } |
|
3417 jio_snprintf(buf, buflen, "noInstalledCode"); |
|
3418 return buf; |
|
3419 } |
|
3420 #endif |