Mercurial > hg > graal-compiler
comparison src/share/vm/code/nmethod.cpp @ 1930:2d26b0046e0d
Merge.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Tue, 30 Nov 2010 14:53:30 +0100 |
parents | abc670a709dc a222fcfba398 |
children | 48bbaead8b6c |
comparison
equal
deleted
inserted
replaced
1484:6b7001391c97 | 1930:2d26b0046e0d |
---|---|
1 /* | 1 /* |
2 * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
14 * | 14 * |
15 * You should have received a copy of the GNU General Public License version | 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, | 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. | 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 * | 18 * |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | 20 * or visit www.oracle.com if you need additional information or have any |
21 * have any questions. | 21 * questions. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 # include "incls/_precompiled.incl" | 25 # include "incls/_precompiled.incl" |
26 # include "incls/_nmethod.cpp.incl" | 26 # include "incls/_nmethod.cpp.incl" |
63 bool nmethod::is_compiled_by_c2() const { | 63 bool nmethod::is_compiled_by_c2() const { |
64 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing | 64 if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing |
65 if (is_native_method()) return false; | 65 if (is_native_method()) return false; |
66 return compiler()->is_c2(); | 66 return compiler()->is_c2(); |
67 } | 67 } |
68 bool nmethod::is_compiled_by_shark() const { | |
69 if (is_native_method()) return false; | |
70 assert(compiler() != NULL, "must be"); | |
71 return compiler()->is_shark(); | |
72 } | |
68 | 73 |
69 | 74 |
70 | 75 |
71 //--------------------------------------------------------------------------------- | 76 //--------------------------------------------------------------------------------- |
72 // NMethod statistics | 77 // NMethod statistics |
80 static | 85 static |
81 struct nmethod_stats_struct { | 86 struct nmethod_stats_struct { |
82 int nmethod_count; | 87 int nmethod_count; |
83 int total_size; | 88 int total_size; |
84 int relocation_size; | 89 int relocation_size; |
85 int code_size; | 90 int consts_size; |
91 int insts_size; | |
86 int stub_size; | 92 int stub_size; |
87 int consts_size; | |
88 int scopes_data_size; | 93 int scopes_data_size; |
89 int scopes_pcs_size; | 94 int scopes_pcs_size; |
90 int dependencies_size; | 95 int dependencies_size; |
91 int handler_table_size; | 96 int handler_table_size; |
92 int nul_chk_table_size; | 97 int nul_chk_table_size; |
94 | 99 |
95 void note_nmethod(nmethod* nm) { | 100 void note_nmethod(nmethod* nm) { |
96 nmethod_count += 1; | 101 nmethod_count += 1; |
97 total_size += nm->size(); | 102 total_size += nm->size(); |
98 relocation_size += nm->relocation_size(); | 103 relocation_size += nm->relocation_size(); |
99 code_size += nm->code_size(); | 104 consts_size += nm->consts_size(); |
105 insts_size += nm->insts_size(); | |
100 stub_size += nm->stub_size(); | 106 stub_size += nm->stub_size(); |
101 consts_size += nm->consts_size(); | 107 oops_size += nm->oops_size(); |
102 scopes_data_size += nm->scopes_data_size(); | 108 scopes_data_size += nm->scopes_data_size(); |
103 scopes_pcs_size += nm->scopes_pcs_size(); | 109 scopes_pcs_size += nm->scopes_pcs_size(); |
104 dependencies_size += nm->dependencies_size(); | 110 dependencies_size += nm->dependencies_size(); |
105 handler_table_size += nm->handler_table_size(); | 111 handler_table_size += nm->handler_table_size(); |
106 nul_chk_table_size += nm->nul_chk_table_size(); | 112 nul_chk_table_size += nm->nul_chk_table_size(); |
107 oops_size += nm->oops_size(); | |
108 } | 113 } |
109 void print_nmethod_stats() { | 114 void print_nmethod_stats() { |
110 if (nmethod_count == 0) return; | 115 if (nmethod_count == 0) return; |
111 tty->print_cr("Statistics for %d bytecoded nmethods:", nmethod_count); | 116 tty->print_cr("Statistics for %d bytecoded nmethods:", nmethod_count); |
112 if (total_size != 0) tty->print_cr(" total in heap = %d", total_size); | 117 if (total_size != 0) tty->print_cr(" total in heap = %d", total_size); |
113 if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size); | 118 if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size); |
114 if (code_size != 0) tty->print_cr(" main code = %d", code_size); | 119 if (consts_size != 0) tty->print_cr(" constants = %d", consts_size); |
120 if (insts_size != 0) tty->print_cr(" main code = %d", insts_size); | |
115 if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size); | 121 if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size); |
116 if (consts_size != 0) tty->print_cr(" constants = %d", consts_size); | 122 if (oops_size != 0) tty->print_cr(" oops = %d", oops_size); |
117 if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size); | 123 if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size); |
118 if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size); | 124 if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size); |
119 if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size); | 125 if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size); |
120 if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size); | 126 if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size); |
121 if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size); | 127 if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size); |
122 if (oops_size != 0) tty->print_cr(" oops = %d", oops_size); | |
123 } | 128 } |
124 | 129 |
125 int native_nmethod_count; | 130 int native_nmethod_count; |
126 int native_total_size; | 131 int native_total_size; |
127 int native_relocation_size; | 132 int native_relocation_size; |
128 int native_code_size; | 133 int native_insts_size; |
129 int native_oops_size; | 134 int native_oops_size; |
130 void note_native_nmethod(nmethod* nm) { | 135 void note_native_nmethod(nmethod* nm) { |
131 native_nmethod_count += 1; | 136 native_nmethod_count += 1; |
132 native_total_size += nm->size(); | 137 native_total_size += nm->size(); |
133 native_relocation_size += nm->relocation_size(); | 138 native_relocation_size += nm->relocation_size(); |
134 native_code_size += nm->code_size(); | 139 native_insts_size += nm->insts_size(); |
135 native_oops_size += nm->oops_size(); | 140 native_oops_size += nm->oops_size(); |
136 } | 141 } |
137 void print_native_nmethod_stats() { | 142 void print_native_nmethod_stats() { |
138 if (native_nmethod_count == 0) return; | 143 if (native_nmethod_count == 0) return; |
139 tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count); | 144 tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count); |
140 if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size); | 145 if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size); |
141 if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size); | 146 if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size); |
142 if (native_code_size != 0) tty->print_cr(" N. main code = %d", native_code_size); | 147 if (native_insts_size != 0) tty->print_cr(" N. main code = %d", native_insts_size); |
143 if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size); | 148 if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size); |
144 } | 149 } |
145 | 150 |
146 int pc_desc_resets; // number of resets (= number of caches) | 151 int pc_desc_resets; // number of resets (= number of caches) |
147 int pc_desc_queries; // queries to nmethod::find_pc_desc | 152 int pc_desc_queries; // queries to nmethod::find_pc_desc |
395 | 400 |
396 | 401 |
397 //-------------end of code for ExceptionCache-------------- | 402 //-------------end of code for ExceptionCache-------------- |
398 | 403 |
399 | 404 |
400 void nmFlags::clear() { | |
401 assert(sizeof(nmFlags) == sizeof(int), "using more than one word for nmFlags"); | |
402 *(jint*)this = 0; | |
403 } | |
404 | |
405 int nmethod::total_size() const { | 405 int nmethod::total_size() const { |
406 return | 406 return |
407 code_size() + | 407 consts_size() + |
408 insts_size() + | |
408 stub_size() + | 409 stub_size() + |
409 consts_size() + | |
410 scopes_data_size() + | 410 scopes_data_size() + |
411 scopes_pcs_size() + | 411 scopes_pcs_size() + |
412 handler_table_size() + | 412 handler_table_size() + |
413 nul_chk_table_size(); | 413 nul_chk_table_size(); |
414 } | 414 } |
417 if (is_osr_method()) return "osr"; | 417 if (is_osr_method()) return "osr"; |
418 if (method() != NULL && is_native_method()) return "c2n"; | 418 if (method() != NULL && is_native_method()) return "c2n"; |
419 return NULL; | 419 return NULL; |
420 } | 420 } |
421 | 421 |
422 // %%% This variable is no longer used? | 422 // Fill in default values for various flag fields |
423 int nmethod::_zombie_instruction_size = NativeJump::instruction_size; | 423 void nmethod::init_defaults() { |
424 _state = alive; | |
425 _marked_for_reclamation = 0; | |
426 _has_flushed_dependencies = 0; | |
427 _speculatively_disconnected = 0; | |
428 _has_unsafe_access = 0; | |
429 _has_method_handle_invokes = 0; | |
430 _marked_for_deoptimization = 0; | |
431 _lock_count = 0; | |
432 _stack_traversal_mark = 0; | |
433 _unload_reported = false; // jvmti state | |
434 | |
435 NOT_PRODUCT(_has_debug_info = false); | |
436 #ifdef ASSERT | |
437 _oops_are_stale = false; | |
438 #endif | |
439 | |
440 _oops_do_mark_link = NULL; | |
441 _jmethod_id = NULL; | |
442 _osr_link = NULL; | |
443 _scavenge_root_link = NULL; | |
444 _scavenge_root_state = 0; | |
445 _saved_nmethod_link = NULL; | |
446 _compiler = NULL; | |
447 | |
448 #ifdef HAVE_DTRACE_H | |
449 _trap_offset = 0; | |
450 #endif // def HAVE_DTRACE_H | |
451 } | |
424 | 452 |
425 | 453 |
426 nmethod* nmethod::new_native_nmethod(methodHandle method, | 454 nmethod* nmethod::new_native_nmethod(methodHandle method, |
427 CodeBuffer *code_buffer, | 455 CodeBuffer *code_buffer, |
428 int vep_offset, | 456 int vep_offset, |
578 { | 606 { |
579 { | 607 { |
580 debug_only(No_Safepoint_Verifier nsv;) | 608 debug_only(No_Safepoint_Verifier nsv;) |
581 assert_locked_or_safepoint(CodeCache_lock); | 609 assert_locked_or_safepoint(CodeCache_lock); |
582 | 610 |
583 NOT_PRODUCT(_has_debug_info = false); | 611 init_defaults(); |
584 _oops_do_mark_link = NULL; | |
585 _method = method; | 612 _method = method; |
586 _entry_bci = InvocationEntryBci; | 613 _entry_bci = InvocationEntryBci; |
587 _osr_link = NULL; | |
588 _scavenge_root_link = NULL; | |
589 _scavenge_root_state = 0; | |
590 _saved_nmethod_link = NULL; | |
591 _compiler = NULL; | |
592 // We have no exception handler or deopt handler make the | 614 // We have no exception handler or deopt handler make the |
593 // values something that will never match a pc like the nmethod vtable entry | 615 // values something that will never match a pc like the nmethod vtable entry |
594 _exception_offset = 0; | 616 _exception_offset = 0; |
595 _deoptimize_offset = 0; | 617 _deoptimize_offset = 0; |
596 _deoptimize_mh_offset = 0; | 618 _deoptimize_mh_offset = 0; |
597 _orig_pc_offset = 0; | 619 _orig_pc_offset = 0; |
598 #ifdef HAVE_DTRACE_H | 620 |
599 _trap_offset = 0; | 621 _consts_offset = data_offset(); |
600 #endif // def HAVE_DTRACE_H | |
601 _stub_offset = data_offset(); | 622 _stub_offset = data_offset(); |
602 _consts_offset = data_offset(); | 623 _oops_offset = data_offset(); |
603 _scopes_data_offset = data_offset(); | 624 _scopes_data_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); |
604 _scopes_pcs_offset = _scopes_data_offset; | 625 _scopes_pcs_offset = _scopes_data_offset; |
605 _dependencies_offset = _scopes_pcs_offset; | 626 _dependencies_offset = _scopes_pcs_offset; |
606 _handler_table_offset = _dependencies_offset; | 627 _handler_table_offset = _dependencies_offset; |
607 _nul_chk_table_offset = _handler_table_offset; | 628 _nul_chk_table_offset = _handler_table_offset; |
608 _nmethod_end_offset = _nul_chk_table_offset; | 629 _nmethod_end_offset = _nul_chk_table_offset; |
609 _compile_id = 0; // default | 630 _compile_id = 0; // default |
610 _comp_level = CompLevel_none; | 631 _comp_level = CompLevel_none; |
611 _entry_point = instructions_begin(); | 632 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); |
612 _verified_entry_point = instructions_begin() + offsets->value(CodeOffsets::Verified_Entry); | 633 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); |
613 _osr_entry_point = NULL; | 634 _osr_entry_point = NULL; |
614 _exception_cache = NULL; | 635 _exception_cache = NULL; |
615 _pc_desc_cache.reset_to(NULL); | 636 _pc_desc_cache.reset_to(NULL); |
616 | 637 |
617 flags.clear(); | |
618 flags.state = alive; | |
619 _markedForDeoptimization = 0; | |
620 | |
621 _lock_count = 0; | |
622 _stack_traversal_mark = 0; | |
623 | |
624 code_buffer->copy_oops_to(this); | 638 code_buffer->copy_oops_to(this); |
625 debug_only(verify_scavenge_root_oops()); | 639 debug_only(verify_scavenge_root_oops()); |
626 CodeCache::commit(this); | 640 CodeCache::commit(this); |
627 VTune::create_nmethod(this); | |
628 } | 641 } |
629 | 642 |
630 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { | 643 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { |
631 ttyLocker ttyl; // keep the following output all in one block | 644 ttyLocker ttyl; // keep the following output all in one block |
632 // This output goes directly to the tty, not the compiler log. | 645 // This output goes directly to the tty, not the compiler log. |
670 { | 683 { |
671 { | 684 { |
672 debug_only(No_Safepoint_Verifier nsv;) | 685 debug_only(No_Safepoint_Verifier nsv;) |
673 assert_locked_or_safepoint(CodeCache_lock); | 686 assert_locked_or_safepoint(CodeCache_lock); |
674 | 687 |
675 NOT_PRODUCT(_has_debug_info = false); | 688 init_defaults(); |
676 _oops_do_mark_link = NULL; | |
677 _method = method; | 689 _method = method; |
678 _entry_bci = InvocationEntryBci; | 690 _entry_bci = InvocationEntryBci; |
679 _osr_link = NULL; | |
680 _scavenge_root_link = NULL; | |
681 _scavenge_root_state = 0; | |
682 _compiler = NULL; | |
683 // We have no exception handler or deopt handler make the | 691 // We have no exception handler or deopt handler make the |
684 // values something that will never match a pc like the nmethod vtable entry | 692 // values something that will never match a pc like the nmethod vtable entry |
685 _exception_offset = 0; | 693 _exception_offset = 0; |
686 _deoptimize_offset = 0; | 694 _deoptimize_offset = 0; |
687 _deoptimize_mh_offset = 0; | 695 _deoptimize_mh_offset = 0; |
688 _unwind_handler_offset = -1; | 696 _unwind_handler_offset = -1; |
689 _trap_offset = offsets->value(CodeOffsets::Dtrace_trap); | 697 _trap_offset = offsets->value(CodeOffsets::Dtrace_trap); |
690 _orig_pc_offset = 0; | 698 _orig_pc_offset = 0; |
699 _consts_offset = data_offset(); | |
691 _stub_offset = data_offset(); | 700 _stub_offset = data_offset(); |
692 _consts_offset = data_offset(); | 701 _oops_offset = data_offset(); |
693 _scopes_data_offset = data_offset(); | 702 _scopes_data_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); |
694 _scopes_pcs_offset = _scopes_data_offset; | 703 _scopes_pcs_offset = _scopes_data_offset; |
695 _dependencies_offset = _scopes_pcs_offset; | 704 _dependencies_offset = _scopes_pcs_offset; |
696 _handler_table_offset = _dependencies_offset; | 705 _handler_table_offset = _dependencies_offset; |
697 _nul_chk_table_offset = _handler_table_offset; | 706 _nul_chk_table_offset = _handler_table_offset; |
698 _nmethod_end_offset = _nul_chk_table_offset; | 707 _nmethod_end_offset = _nul_chk_table_offset; |
699 _compile_id = 0; // default | 708 _compile_id = 0; // default |
700 _comp_level = CompLevel_none; | 709 _comp_level = CompLevel_none; |
701 _entry_point = instructions_begin(); | 710 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); |
702 _verified_entry_point = instructions_begin() + offsets->value(CodeOffsets::Verified_Entry); | 711 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); |
703 _osr_entry_point = NULL; | 712 _osr_entry_point = NULL; |
704 _exception_cache = NULL; | 713 _exception_cache = NULL; |
705 _pc_desc_cache.reset_to(NULL); | 714 _pc_desc_cache.reset_to(NULL); |
706 | 715 |
707 flags.clear(); | |
708 flags.state = alive; | |
709 _markedForDeoptimization = 0; | |
710 | |
711 _lock_count = 0; | |
712 _stack_traversal_mark = 0; | |
713 | |
714 code_buffer->copy_oops_to(this); | 716 code_buffer->copy_oops_to(this); |
715 debug_only(verify_scavenge_root_oops()); | 717 debug_only(verify_scavenge_root_oops()); |
716 CodeCache::commit(this); | 718 CodeCache::commit(this); |
717 VTune::create_nmethod(this); | |
718 } | 719 } |
719 | 720 |
720 if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { | 721 if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { |
721 ttyLocker ttyl; // keep the following output all in one block | 722 ttyLocker ttyl; // keep the following output all in one block |
722 // This output goes directly to the tty, not the compiler log. | 723 // This output goes directly to the tty, not the compiler log. |
777 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); | 778 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); |
778 { | 779 { |
779 debug_only(No_Safepoint_Verifier nsv;) | 780 debug_only(No_Safepoint_Verifier nsv;) |
780 assert_locked_or_safepoint(CodeCache_lock); | 781 assert_locked_or_safepoint(CodeCache_lock); |
781 | 782 |
782 NOT_PRODUCT(_has_debug_info = false); | 783 init_defaults(); |
783 _oops_do_mark_link = NULL; | |
784 _method = method; | 784 _method = method; |
785 _entry_bci = entry_bci; | |
785 _compile_id = compile_id; | 786 _compile_id = compile_id; |
786 _comp_level = comp_level; | 787 _comp_level = comp_level; |
787 _entry_bci = entry_bci; | |
788 _osr_link = NULL; | |
789 _scavenge_root_link = NULL; | |
790 _scavenge_root_state = 0; | |
791 _compiler = compiler; | 788 _compiler = compiler; |
792 _orig_pc_offset = orig_pc_offset; | 789 _orig_pc_offset = orig_pc_offset; |
793 #ifdef HAVE_DTRACE_H | 790 |
794 _trap_offset = 0; | 791 // Section offsets |
795 #endif // def HAVE_DTRACE_H | 792 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); |
796 _stub_offset = instructions_offset() + code_buffer->total_offset_of(code_buffer->stubs()->start()); | 793 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); |
797 | 794 |
798 // Exception handler and deopt handler are in the stub section | 795 // Exception handler and deopt handler are in the stub section |
799 if (UseC1X) { | 796 if (UseC1X) { |
800 // c1x produces no stub section | 797 // c1x produces no stub section |
801 _exception_offset = instructions_offset() + offsets->value(CodeOffsets::Exceptions); | 798 _exception_offset = instructions_offset() + offsets->value(CodeOffsets::Exceptions); |
802 _deoptimize_offset = instructions_offset() + offsets->value(CodeOffsets::Deopt); | 799 _deoptimize_offset = instructions_offset() + offsets->value(CodeOffsets::Deopt); |
803 _deoptimize_mh_offset = instructions_offset() + offsets->value(CodeOffsets::DeoptMH); | 800 if (has_method_handle_invokes()) { |
801 _deoptimize_mh_offset = instructions_offset() + offsets->value(CodeOffsets::DeoptMH); | |
802 } else { | |
803 _deoptimize_mh_offset = -1; | |
804 } | |
804 } else { | 805 } else { |
805 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions); | 806 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions); |
806 _deoptimize_offset = _stub_offset + offsets->value(CodeOffsets::Deopt); | 807 _deoptimize_offset = _stub_offset + offsets->value(CodeOffsets::Deopt); |
807 _deoptimize_mh_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH); | 808 if (has_method_handle_invokes()) { |
809 _deoptimize_mh_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH); | |
810 } else { | |
811 _deoptimize_mh_offset = -1; | |
812 } | |
808 } | 813 } |
809 if (offsets->value(CodeOffsets::UnwindHandler) != -1) { | 814 if (offsets->value(CodeOffsets::UnwindHandler) != -1) { |
810 _unwind_handler_offset = instructions_offset() + offsets->value(CodeOffsets::UnwindHandler); | 815 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler); |
811 } else { | 816 } else { |
812 _unwind_handler_offset = -1; | 817 _unwind_handler_offset = -1; |
813 } | 818 } |
814 _consts_offset = instructions_offset() + code_buffer->total_offset_of(code_buffer->consts()->start()); | 819 |
815 _scopes_data_offset = data_offset(); | 820 _oops_offset = data_offset(); |
816 _scopes_pcs_offset = _scopes_data_offset + round_to(debug_info->data_size (), oopSize); | 821 _scopes_data_offset = _oops_offset + round_to(code_buffer->total_oop_size (), oopSize); |
822 _scopes_pcs_offset = _scopes_data_offset + round_to(debug_info->data_size (), oopSize); | |
817 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size()); | 823 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size()); |
818 _handler_table_offset = _dependencies_offset + round_to(dependencies->size_in_bytes (), oopSize); | 824 _handler_table_offset = _dependencies_offset + round_to(dependencies->size_in_bytes (), oopSize); |
819 _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize); | 825 _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize); |
820 _nmethod_end_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize); | 826 _nmethod_end_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize); |
821 | 827 |
822 _entry_point = instructions_begin(); | 828 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); |
823 _verified_entry_point = instructions_begin() + offsets->value(CodeOffsets::Verified_Entry); | 829 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); |
824 _osr_entry_point = instructions_begin() + offsets->value(CodeOffsets::OSR_Entry); | 830 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry); |
825 _exception_cache = NULL; | 831 _exception_cache = NULL; |
826 _pc_desc_cache.reset_to(scopes_pcs_begin()); | 832 _pc_desc_cache.reset_to(scopes_pcs_begin()); |
827 | |
828 flags.clear(); | |
829 flags.state = alive; | |
830 _markedForDeoptimization = 0; | |
831 | |
832 _unload_reported = false; // jvmti state | |
833 | |
834 _lock_count = 0; | |
835 _stack_traversal_mark = 0; | |
836 | 833 |
837 // Copy contents of ScopeDescRecorder to nmethod | 834 // Copy contents of ScopeDescRecorder to nmethod |
838 code_buffer->copy_oops_to(this); | 835 code_buffer->copy_oops_to(this); |
839 debug_info->copy_to(this); | 836 debug_info->copy_to(this); |
840 dependencies->copy_to(this); | 837 dependencies->copy_to(this); |
842 CodeCache::add_scavenge_root_nmethod(this); | 839 CodeCache::add_scavenge_root_nmethod(this); |
843 } | 840 } |
844 debug_only(verify_scavenge_root_oops()); | 841 debug_only(verify_scavenge_root_oops()); |
845 | 842 |
846 CodeCache::commit(this); | 843 CodeCache::commit(this); |
847 | |
848 VTune::create_nmethod(this); | |
849 | 844 |
850 // Copy contents of ExceptionHandlerTable to nmethod | 845 // Copy contents of ExceptionHandlerTable to nmethod |
851 handler_table->copy_to(this); | 846 handler_table->copy_to(this); |
852 nul_chk_table->copy_to(this); | 847 nul_chk_table->copy_to(this); |
853 | 848 |
881 const char* nm_kind = compile_kind(); | 876 const char* nm_kind = compile_kind(); |
882 if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind); | 877 if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind); |
883 if (compiler() != NULL) { | 878 if (compiler() != NULL) { |
884 log->print(" compiler='%s'", compiler()->name()); | 879 log->print(" compiler='%s'", compiler()->name()); |
885 } | 880 } |
886 #ifdef TIERED | 881 if (TieredCompilation) { |
887 log->print(" level='%d'", comp_level()); | 882 log->print(" level='%d'", comp_level()); |
888 #endif // TIERED | 883 } |
889 } | 884 } |
890 | 885 |
891 | 886 |
892 #define LOG_OFFSET(log, name) \ | 887 #define LOG_OFFSET(log, name) \ |
893 if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \ | 888 if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \ |
899 if (LogCompilation && xtty != NULL) { | 894 if (LogCompilation && xtty != NULL) { |
900 ttyLocker ttyl; | 895 ttyLocker ttyl; |
901 HandleMark hm; | 896 HandleMark hm; |
902 xtty->begin_elem("nmethod"); | 897 xtty->begin_elem("nmethod"); |
903 log_identity(xtty); | 898 log_identity(xtty); |
904 xtty->print(" entry='" INTPTR_FORMAT "' size='%d'", | 899 xtty->print(" entry='" INTPTR_FORMAT "' size='%d'", code_begin(), size()); |
905 instructions_begin(), size()); | |
906 xtty->print(" address='" INTPTR_FORMAT "'", (intptr_t) this); | 900 xtty->print(" address='" INTPTR_FORMAT "'", (intptr_t) this); |
907 | 901 |
908 LOG_OFFSET(xtty, relocation); | 902 LOG_OFFSET(xtty, relocation); |
909 LOG_OFFSET(xtty, code); | 903 LOG_OFFSET(xtty, consts); |
904 LOG_OFFSET(xtty, insts); | |
910 LOG_OFFSET(xtty, stub); | 905 LOG_OFFSET(xtty, stub); |
911 LOG_OFFSET(xtty, consts); | |
912 LOG_OFFSET(xtty, scopes_data); | 906 LOG_OFFSET(xtty, scopes_data); |
913 LOG_OFFSET(xtty, scopes_pcs); | 907 LOG_OFFSET(xtty, scopes_pcs); |
914 LOG_OFFSET(xtty, dependencies); | 908 LOG_OFFSET(xtty, dependencies); |
915 LOG_OFFSET(xtty, handler_table); | 909 LOG_OFFSET(xtty, handler_table); |
916 LOG_OFFSET(xtty, nul_chk_table); | 910 LOG_OFFSET(xtty, nul_chk_table); |
923 } | 917 } |
924 | 918 |
925 #undef LOG_OFFSET | 919 #undef LOG_OFFSET |
926 | 920 |
927 | 921 |
922 void nmethod::print_compilation(outputStream *st, const char *method_name, const char *title, | |
923 methodOop method, bool is_blocking, int compile_id, int bci, int comp_level) { | |
924 bool is_synchronized = false, has_xhandler = false, is_native = false; | |
925 int code_size = -1; | |
926 if (method != NULL) { | |
927 is_synchronized = method->is_synchronized(); | |
928 has_xhandler = method->has_exception_handler(); | |
929 is_native = method->is_native(); | |
930 code_size = method->code_size(); | |
931 } | |
932 // print compilation number | |
933 st->print("%7d %3d", (int)tty->time_stamp().milliseconds(), compile_id); | |
934 | |
935 // print method attributes | |
936 const bool is_osr = bci != InvocationEntryBci; | |
937 const char blocking_char = is_blocking ? 'b' : ' '; | |
938 const char compile_type = is_osr ? '%' : ' '; | |
939 const char sync_char = is_synchronized ? 's' : ' '; | |
940 const char exception_char = has_xhandler ? '!' : ' '; | |
941 const char native_char = is_native ? 'n' : ' '; | |
942 st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char); | |
943 if (TieredCompilation) { | |
944 st->print("%d ", comp_level); | |
945 } | |
946 | |
947 // print optional title | |
948 bool do_nl = false; | |
949 if (title != NULL) { | |
950 int tlen = (int) strlen(title); | |
951 bool do_nl = false; | |
952 if (tlen > 0 && title[tlen-1] == '\n') { tlen--; do_nl = true; } | |
953 st->print("%.*s", tlen, title); | |
954 } else { | |
955 do_nl = true; | |
956 } | |
957 | |
958 // print method name string if given | |
959 if (method_name != NULL) { | |
960 st->print(method_name); | |
961 } else { | |
962 // otherwise as the method to print itself | |
963 if (method != NULL && !Universe::heap()->is_gc_active()) { | |
964 method->print_short_name(st); | |
965 } else { | |
966 st->print("(method)"); | |
967 } | |
968 } | |
969 | |
970 if (method != NULL) { | |
971 // print osr_bci if any | |
972 if (is_osr) st->print(" @ %d", bci); | |
973 // print method size | |
974 st->print(" (%d bytes)", code_size); | |
975 } | |
976 if (do_nl) st->cr(); | |
977 } | |
978 | |
928 // Print out more verbose output usually for a newly created nmethod. | 979 // Print out more verbose output usually for a newly created nmethod. |
929 void nmethod::print_on(outputStream* st, const char* title) const { | 980 void nmethod::print_on(outputStream* st, const char* title) const { |
930 if (st != NULL) { | 981 if (st != NULL) { |
931 ttyLocker ttyl; | 982 ttyLocker ttyl; |
932 // Print a little tag line that looks like +PrintCompilation output: | 983 print_compilation(st, /*method_name*/NULL, title, |
933 int tlen = (int) strlen(title); | 984 method(), /*is_blocking*/false, |
934 bool do_nl = false; | 985 compile_id(), |
935 if (tlen > 0 && title[tlen-1] == '\n') { tlen--; do_nl = true; } | 986 is_osr_method() ? osr_entry_bci() : InvocationEntryBci, |
936 st->print("%3d%c %.*s", | 987 comp_level()); |
937 compile_id(), | |
938 is_osr_method() ? '%' : | |
939 method() != NULL && | |
940 is_native_method() ? 'n' : ' ', | |
941 tlen, title); | |
942 #ifdef TIERED | |
943 st->print(" (%d) ", comp_level()); | |
944 #endif // TIERED | |
945 if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this); | 988 if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this); |
946 if (Universe::heap()->is_gc_active() && method() != NULL) { | |
947 st->print("(method)"); | |
948 } else if (method() != NULL) { | |
949 method()->print_short_name(st); | |
950 if (is_osr_method()) | |
951 st->print(" @ %d", osr_entry_bci()); | |
952 if (method()->code_size() > 0) | |
953 st->print(" (%d bytes)", method()->code_size()); | |
954 } | |
955 | |
956 if (do_nl) st->cr(); | |
957 } | 989 } |
958 } | 990 } |
959 | 991 |
960 | 992 |
961 void nmethod::print_nmethod(bool printmethod) { | 993 void nmethod::print_nmethod(bool printmethod) { |
990 xtty->tail("print_nmethod"); | 1022 xtty->tail("print_nmethod"); |
991 } | 1023 } |
992 } | 1024 } |
993 | 1025 |
994 | 1026 |
995 void nmethod::set_version(int v) { | 1027 // Promote one word from an assembly-time handle to a live embedded oop. |
996 flags.version = v; | 1028 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) { |
1029 if (handle == NULL || | |
1030 // As a special case, IC oops are initialized to 1 or -1. | |
1031 handle == (jobject) Universe::non_oop_word()) { | |
1032 (*dest) = (oop) handle; | |
1033 } else { | |
1034 (*dest) = JNIHandles::resolve_non_null(handle); | |
1035 } | |
1036 } | |
1037 | |
1038 | |
1039 void nmethod::copy_oops(GrowableArray<jobject>* array) { | |
1040 //assert(oops_size() == 0, "do this handshake just once, please"); | |
1041 int length = array->length(); | |
1042 assert((address)(oops_begin() + length) <= data_end(), "oops big enough"); | |
1043 oop* dest = oops_begin(); | |
1044 for (int index = 0 ; index < length; index++) { | |
1045 initialize_immediate_oop(&dest[index], array->at(index)); | |
1046 } | |
1047 | |
1048 // Now we can fix up all the oops in the code. We need to do this | |
1049 // in the code because the assembler uses jobjects as placeholders. | |
1050 // The code and relocations have already been initialized by the | |
1051 // CodeBlob constructor, so it is valid even at this early point to | |
1052 // iterate over relocations and patch the code. | |
1053 fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true); | |
1054 } | |
1055 | |
1056 | |
1057 bool nmethod::is_at_poll_return(address pc) { | |
1058 RelocIterator iter(this, pc, pc+1); | |
1059 while (iter.next()) { | |
1060 if (iter.type() == relocInfo::poll_return_type) | |
1061 return true; | |
1062 } | |
1063 return false; | |
1064 } | |
1065 | |
1066 | |
1067 bool nmethod::is_at_poll_or_poll_return(address pc) { | |
1068 RelocIterator iter(this, pc, pc+1); | |
1069 while (iter.next()) { | |
1070 relocInfo::relocType t = iter.type(); | |
1071 if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) | |
1072 return true; | |
1073 } | |
1074 return false; | |
1075 } | |
1076 | |
1077 | |
1078 void nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) { | |
1079 // re-patch all oop-bearing instructions, just in case some oops moved | |
1080 RelocIterator iter(this, begin, end); | |
1081 while (iter.next()) { | |
1082 if (iter.type() == relocInfo::oop_type) { | |
1083 oop_Relocation* reloc = iter.oop_reloc(); | |
1084 if (initialize_immediates && reloc->oop_is_immediate()) { | |
1085 oop* dest = reloc->oop_addr(); | |
1086 initialize_immediate_oop(dest, (jobject) *dest); | |
1087 } | |
1088 // Refresh the oop-related bits of this instruction. | |
1089 reloc->fix_oop_relocation(); | |
1090 } | |
1091 | |
1092 // There must not be any interfering patches or breakpoints. | |
1093 assert(!(iter.type() == relocInfo::breakpoint_type | |
1094 && iter.breakpoint_reloc()->active()), | |
1095 "no active breakpoint"); | |
1096 } | |
997 } | 1097 } |
998 | 1098 |
999 | 1099 |
1000 ScopeDesc* nmethod::scope_desc_at(address pc) { | 1100 ScopeDesc* nmethod::scope_desc_at(address pc) { |
1001 PcDesc* pd = pc_desc_at(pc); | 1101 PcDesc* pd = pc_desc_at(pc); |
1019 } | 1119 } |
1020 | 1120 |
1021 | 1121 |
1022 void nmethod::cleanup_inline_caches() { | 1122 void nmethod::cleanup_inline_caches() { |
1023 | 1123 |
1024 assert(SafepointSynchronize::is_at_safepoint() && | 1124 assert_locked_or_safepoint(CompiledIC_lock); |
1025 !CompiledIC_lock->is_locked() && | |
1026 !Patching_lock->is_locked(), "no threads must be updating the inline caches by them selfs"); | |
1027 | 1125 |
1028 // If the method is not entrant or zombie then a JMP is plastered over the | 1126 // If the method is not entrant or zombie then a JMP is plastered over the |
1029 // first few bytes. If an oop in the old code was there, that oop | 1127 // first few bytes. If an oop in the old code was there, that oop |
1030 // should not get GC'd. Skip the first few bytes of oops on | 1128 // should not get GC'd. Skip the first few bytes of oops on |
1031 // not-entrant methods. | 1129 // not-entrant methods. |
1070 } | 1168 } |
1071 | 1169 |
1072 // This is a private interface with the sweeper. | 1170 // This is a private interface with the sweeper. |
1073 void nmethod::mark_as_seen_on_stack() { | 1171 void nmethod::mark_as_seen_on_stack() { |
1074 assert(is_not_entrant(), "must be a non-entrant method"); | 1172 assert(is_not_entrant(), "must be a non-entrant method"); |
1173 // Set the traversal mark to ensure that the sweeper does 2 | |
1174 // cleaning passes before moving to zombie. | |
1075 set_stack_traversal_mark(NMethodSweeper::traversal_count()); | 1175 set_stack_traversal_mark(NMethodSweeper::traversal_count()); |
1076 } | 1176 } |
1077 | 1177 |
1078 // Tell if a non-entrant method can be converted to a zombie (i.e., there is no activations on the stack) | 1178 // Tell if a non-entrant method can be converted to a zombie (i.e., there is no activations on the stack) |
1079 bool nmethod::can_not_entrant_be_converted() { | 1179 bool nmethod::can_not_entrant_be_converted() { |
1080 assert(is_not_entrant(), "must be a non-entrant method"); | 1180 assert(is_not_entrant(), "must be a non-entrant method"); |
1081 assert(SafepointSynchronize::is_at_safepoint(), "must be called during a safepoint"); | |
1082 | 1181 |
1083 // Since the nmethod sweeper only does partial sweep the sweeper's traversal | 1182 // Since the nmethod sweeper only does partial sweep the sweeper's traversal |
1084 // count can be greater than the stack traversal count before it hits the | 1183 // count can be greater than the stack traversal count before it hits the |
1085 // nmethod for the second time. | 1184 // nmethod for the second time. |
1086 return stack_traversal_mark()+1 < NMethodSweeper::traversal_count(); | 1185 return stack_traversal_mark()+1 < NMethodSweeper::traversal_count(); |
1087 } | 1186 } |
1088 | 1187 |
1089 void nmethod::inc_decompile_count() { | 1188 void nmethod::inc_decompile_count() { |
1189 if (!is_compiled_by_c2()) return; | |
1090 // Could be gated by ProfileTraps, but do not bother... | 1190 // Could be gated by ProfileTraps, but do not bother... |
1091 methodOop m = method(); | 1191 methodOop m = method(); |
1092 if (m == NULL) return; | 1192 if (m == NULL) return; |
1093 methodDataOop mdo = m->method_data(); | 1193 methodDataOop mdo = m->method_data(); |
1094 if (mdo == NULL) return; | 1194 if (mdo == NULL) return; |
1132 _method->clear_code(); // Break a cycle | 1232 _method->clear_code(); // Break a cycle |
1133 } | 1233 } |
1134 _method = NULL; // Clear the method of this dead nmethod | 1234 _method = NULL; // Clear the method of this dead nmethod |
1135 } | 1235 } |
1136 // Make the class unloaded - i.e., change state and notify sweeper | 1236 // Make the class unloaded - i.e., change state and notify sweeper |
1137 check_safepoint(); | 1237 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
1138 if (is_in_use()) { | 1238 if (is_in_use()) { |
1139 // Transitioning directly from live to unloaded -- so | 1239 // Transitioning directly from live to unloaded -- so |
1140 // we need to force a cache clean-up; remember this | 1240 // we need to force a cache clean-up; remember this |
1141 // for later on. | 1241 // for later on. |
1142 CodeCache::set_needs_cache_clean(true); | 1242 CodeCache::set_needs_cache_clean(true); |
1143 } | 1243 } |
1144 flags.state = unloaded; | 1244 _state = unloaded; |
1145 | 1245 |
1146 // Log the unloading. | 1246 // Log the unloading. |
1147 log_state_change(); | 1247 log_state_change(); |
1148 | 1248 |
1149 // The methodOop is gone at this point | 1249 // The methodOop is gone at this point |
1165 | 1265 |
1166 void nmethod::log_state_change() const { | 1266 void nmethod::log_state_change() const { |
1167 if (LogCompilation) { | 1267 if (LogCompilation) { |
1168 if (xtty != NULL) { | 1268 if (xtty != NULL) { |
1169 ttyLocker ttyl; // keep the following output all in one block | 1269 ttyLocker ttyl; // keep the following output all in one block |
1170 if (flags.state == unloaded) { | 1270 if (_state == unloaded) { |
1171 xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'", | 1271 xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'", |
1172 os::current_thread_id()); | 1272 os::current_thread_id()); |
1173 } else { | 1273 } else { |
1174 xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s", | 1274 xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s", |
1175 os::current_thread_id(), | 1275 os::current_thread_id(), |
1176 (flags.state == zombie ? " zombie='1'" : "")); | 1276 (_state == zombie ? " zombie='1'" : "")); |
1177 } | 1277 } |
1178 log_identity(xtty); | 1278 log_identity(xtty); |
1179 xtty->stamp(); | 1279 xtty->stamp(); |
1180 xtty->end_elem(); | 1280 xtty->end_elem(); |
1181 } | 1281 } |
1182 } | 1282 } |
1183 if (PrintCompilation && flags.state != unloaded) { | 1283 if (PrintCompilation && _state != unloaded) { |
1184 print_on(tty, flags.state == zombie ? "made zombie " : "made not entrant "); | 1284 print_on(tty, _state == zombie ? "made zombie " : "made not entrant "); |
1185 tty->cr(); | 1285 tty->cr(); |
1186 } | 1286 } |
1187 } | 1287 } |
1188 | 1288 |
1189 // Common functionality for both make_not_entrant and make_zombie | 1289 // Common functionality for both make_not_entrant and make_zombie |
1190 bool nmethod::make_not_entrant_or_zombie(unsigned int state) { | 1290 bool nmethod::make_not_entrant_or_zombie(unsigned int state) { |
1191 assert(state == zombie || state == not_entrant, "must be zombie or not_entrant"); | 1291 assert(state == zombie || state == not_entrant, "must be zombie or not_entrant"); |
1192 | 1292 |
1193 bool was_alive = false; | 1293 // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below. |
1194 | |
1195 // Make sure the nmethod is not flushed in case of a safepoint in code below. | |
1196 nmethodLocker nml(this); | 1294 nmethodLocker nml(this); |
1295 methodHandle the_method(method()); | |
1296 No_Safepoint_Verifier nsv; | |
1197 | 1297 |
1198 { | 1298 { |
1199 // If the method is already zombie there is nothing to do | 1299 // If the method is already zombie there is nothing to do |
1200 if (is_zombie()) { | 1300 if (is_zombie()) { |
1201 return false; | 1301 return false; |
1211 } | 1311 } |
1212 | 1312 |
1213 // Enter critical section. Does not block for safepoint. | 1313 // Enter critical section. Does not block for safepoint. |
1214 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); | 1314 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); |
1215 | 1315 |
1216 if (flags.state == state) { | 1316 if (_state == state) { |
1217 // another thread already performed this transition so nothing | 1317 // another thread already performed this transition so nothing |
1218 // to do, but return false to indicate this. | 1318 // to do, but return false to indicate this. |
1219 return false; | 1319 return false; |
1220 } | 1320 } |
1221 | 1321 |
1222 // The caller can be calling the method statically or through an inline | 1322 // The caller can be calling the method statically or through an inline |
1223 // cache call. | 1323 // cache call. |
1224 if (!is_osr_method() && !is_not_entrant()) { | 1324 if (!is_osr_method() && !is_not_entrant()) { |
1225 NativeJump::patch_verified_entry(entry_point(), verified_entry_point(), | 1325 NativeJump::patch_verified_entry(entry_point(), verified_entry_point(), |
1226 SharedRuntime::get_handle_wrong_method_stub()); | 1326 SharedRuntime::get_handle_wrong_method_stub()); |
1227 assert (NativeJump::instruction_size == nmethod::_zombie_instruction_size, ""); | 1327 } |
1228 } | 1328 |
1229 | 1329 if (is_in_use()) { |
1230 // When the nmethod becomes zombie it is no longer alive so the | 1330 // It's a true state change, so mark the method as decompiled. |
1231 // dependencies must be flushed. nmethods in the not_entrant | 1331 // Do it only for transition from alive. |
1232 // state will be flushed later when the transition to zombie | 1332 inc_decompile_count(); |
1233 // happens or they get unloaded. | 1333 } |
1234 if (state == zombie) { | |
1235 assert(SafepointSynchronize::is_at_safepoint(), "must be done at safepoint"); | |
1236 flush_dependencies(NULL); | |
1237 } else { | |
1238 assert(state == not_entrant, "other cases may need to be handled differently"); | |
1239 } | |
1240 | |
1241 was_alive = is_in_use(); // Read state under lock | |
1242 | 1334 |
1243 // Change state | 1335 // Change state |
1244 flags.state = state; | 1336 _state = state; |
1245 | 1337 |
1246 // Log the transition once | 1338 // Log the transition once |
1247 log_state_change(); | 1339 log_state_change(); |
1248 | 1340 |
1341 // Remove nmethod from method. | |
1342 // We need to check if both the _code and _from_compiled_code_entry_point | |
1343 // refer to this nmethod because there is a race in setting these two fields | |
1344 // in methodOop as seen in bugid 4947125. | |
1345 // If the vep() points to the zombie nmethod, the memory for the nmethod | |
1346 // could be flushed and the compiler and vtable stubs could still call | |
1347 // through it. | |
1348 if (method() != NULL && (method()->code() == this || | |
1349 method()->from_compiled_entry() == verified_entry_point())) { | |
1350 HandleMark hm; | |
1351 method()->clear_code(); | |
1352 } | |
1353 | |
1354 if (state == not_entrant) { | |
1355 mark_as_seen_on_stack(); | |
1356 } | |
1357 | |
1249 } // leave critical region under Patching_lock | 1358 } // leave critical region under Patching_lock |
1250 | 1359 |
1251 if (state == not_entrant) { | 1360 // When the nmethod becomes zombie it is no longer alive so the |
1252 Events::log("Make nmethod not entrant " INTPTR_FORMAT, this); | 1361 // dependencies must be flushed. nmethods in the not_entrant |
1362 // state will be flushed later when the transition to zombie | |
1363 // happens or they get unloaded. | |
1364 if (state == zombie) { | |
1365 { | |
1366 // Flushing dependecies must be done before any possible | |
1367 // safepoint can sneak in, otherwise the oops used by the | |
1368 // dependency logic could have become stale. | |
1369 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
1370 flush_dependencies(NULL); | |
1371 } | |
1372 | |
1373 { | |
1374 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload event | |
1375 // and it hasn't already been reported for this nmethod then report it now. | |
1376 // (the event may have been reported earilier if the GC marked it for unloading). | |
1377 Pause_No_Safepoint_Verifier pnsv(&nsv); | |
1378 post_compiled_method_unload(); | |
1379 } | |
1380 | |
1381 #ifdef ASSERT | |
1382 // It's no longer safe to access the oops section since zombie | |
1383 // nmethods aren't scanned for GC. | |
1384 _oops_are_stale = true; | |
1385 #endif | |
1253 } else { | 1386 } else { |
1254 Events::log("Make nmethod zombie " INTPTR_FORMAT, this); | 1387 assert(state == not_entrant, "other cases may need to be handled differently"); |
1255 } | 1388 } |
1256 | 1389 |
1257 if (TraceCreateZombies) { | 1390 if (TraceCreateZombies) { |
1258 tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", this, (state == not_entrant) ? "not entrant" : "zombie"); | 1391 tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", this, (state == not_entrant) ? "not entrant" : "zombie"); |
1259 } | 1392 } |
1260 | 1393 |
1261 // Make sweeper aware that there is a zombie method that needs to be removed | 1394 // Make sweeper aware that there is a zombie method that needs to be removed |
1262 NMethodSweeper::notify(this); | 1395 NMethodSweeper::notify(this); |
1263 | 1396 |
1264 // not_entrant only stuff | |
1265 if (state == not_entrant) { | |
1266 mark_as_seen_on_stack(); | |
1267 } | |
1268 | |
1269 if (was_alive) { | |
1270 // It's a true state change, so mark the method as decompiled. | |
1271 // Do it only for transition from alive. | |
1272 inc_decompile_count(); | |
1273 } | |
1274 | |
1275 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload event | |
1276 // and it hasn't already been reported for this nmethod then report it now. | |
1277 // (the event may have been reported earilier if the GC marked it for unloading). | |
1278 if (state == zombie) { | |
1279 | |
1280 DTRACE_METHOD_UNLOAD_PROBE(method()); | |
1281 | |
1282 if (JvmtiExport::should_post_compiled_method_unload() && | |
1283 !unload_reported()) { | |
1284 assert(method() != NULL, "checking"); | |
1285 { | |
1286 HandleMark hm; | |
1287 JvmtiExport::post_compiled_method_unload_at_safepoint( | |
1288 method()->jmethod_id(), code_begin()); | |
1289 } | |
1290 set_unload_reported(); | |
1291 } | |
1292 } | |
1293 | |
1294 | |
1295 // Zombie only stuff | |
1296 if (state == zombie) { | |
1297 VTune::delete_nmethod(this); | |
1298 } | |
1299 | |
1300 // Check whether method got unloaded at a safepoint before this, | |
1301 // if so we can skip the flushing steps below | |
1302 if (method() == NULL) return true; | |
1303 | |
1304 // Remove nmethod from method. | |
1305 // We need to check if both the _code and _from_compiled_code_entry_point | |
1306 // refer to this nmethod because there is a race in setting these two fields | |
1307 // in methodOop as seen in bugid 4947125. | |
1308 // If the vep() points to the zombie nmethod, the memory for the nmethod | |
1309 // could be flushed and the compiler and vtable stubs could still call | |
1310 // through it. | |
1311 if (method()->code() == this || | |
1312 method()->from_compiled_entry() == verified_entry_point()) { | |
1313 HandleMark hm; | |
1314 method()->clear_code(); | |
1315 } | |
1316 | |
1317 return true; | 1397 return true; |
1318 } | 1398 } |
1319 | |
1320 | |
1321 #ifndef PRODUCT | |
1322 void nmethod::check_safepoint() { | |
1323 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); | |
1324 } | |
1325 #endif | |
1326 | |
1327 | 1399 |
1328 void nmethod::flush() { | 1400 void nmethod::flush() { |
1329 // Note that there are no valid oops in the nmethod anymore. | 1401 // Note that there are no valid oops in the nmethod anymore. |
1330 assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method"); | 1402 assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method"); |
1331 assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation"); | 1403 assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation"); |
1332 | 1404 |
1333 assert (!is_locked_by_vm(), "locked methods shouldn't be flushed"); | 1405 assert (!is_locked_by_vm(), "locked methods shouldn't be flushed"); |
1334 check_safepoint(); | 1406 assert_locked_or_safepoint(CodeCache_lock); |
1335 | 1407 |
1336 // completely deallocate this method | 1408 // completely deallocate this method |
1337 EventMark m("flushing nmethod " INTPTR_FORMAT " %s", this, ""); | 1409 EventMark m("flushing nmethod " INTPTR_FORMAT " %s", this, ""); |
1338 if (PrintMethodFlushing) { | 1410 if (PrintMethodFlushing) { |
1339 tty->print_cr("*flushing nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT "/Free CodeCache:" SIZE_FORMAT "Kb", | 1411 tty->print_cr("*flushing nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT "/Free CodeCache:" SIZE_FORMAT "Kb", |
1356 } | 1428 } |
1357 | 1429 |
1358 if (is_speculatively_disconnected()) { | 1430 if (is_speculatively_disconnected()) { |
1359 CodeCache::remove_saved_code(this); | 1431 CodeCache::remove_saved_code(this); |
1360 } | 1432 } |
1433 | |
1434 #ifdef SHARK | |
1435 ((SharkCompiler *) compiler())->free_compiled_method(insts_begin()); | |
1436 #endif // SHARK | |
1361 | 1437 |
1362 ((CodeBlob*)(this))->flush(); | 1438 ((CodeBlob*)(this))->flush(); |
1363 | 1439 |
1364 CodeCache::free(this); | 1440 CodeCache::free(this); |
1365 } | 1441 } |
1378 // traversing the dependency information in unsafe. In that case this | 1454 // traversing the dependency information in unsafe. In that case this |
1379 // function is called with a non-NULL argument and this function only | 1455 // function is called with a non-NULL argument and this function only |
1380 // notifies instanceKlasses that are reachable | 1456 // notifies instanceKlasses that are reachable |
1381 | 1457 |
1382 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) { | 1458 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) { |
1383 assert(SafepointSynchronize::is_at_safepoint(), "must be done at safepoint"); | 1459 assert_locked_or_safepoint(CodeCache_lock); |
1384 assert(Universe::heap()->is_gc_active() == (is_alive != NULL), | 1460 assert(Universe::heap()->is_gc_active() == (is_alive != NULL), |
1385 "is_alive is non-NULL if and only if we are called during GC"); | 1461 "is_alive is non-NULL if and only if we are called during GC"); |
1386 if (!has_flushed_dependencies()) { | 1462 if (!has_flushed_dependencies()) { |
1387 set_has_flushed_dependencies(); | 1463 set_has_flushed_dependencies(); |
1388 for (Dependencies::DepStream deps(this); deps.next(); ) { | 1464 for (Dependencies::DepStream deps(this); deps.next(); ) { |
1438 moop->klass_name()->utf8_length(), | 1514 moop->klass_name()->utf8_length(), |
1439 moop->name()->bytes(), | 1515 moop->name()->bytes(), |
1440 moop->name()->utf8_length(), | 1516 moop->name()->utf8_length(), |
1441 moop->signature()->bytes(), | 1517 moop->signature()->bytes(), |
1442 moop->signature()->utf8_length(), | 1518 moop->signature()->utf8_length(), |
1443 code_begin(), code_size()); | 1519 insts_begin(), insts_size()); |
1520 | |
1521 if (JvmtiExport::should_post_compiled_method_load() || | |
1522 JvmtiExport::should_post_compiled_method_unload()) { | |
1523 get_and_cache_jmethod_id(); | |
1524 } | |
1444 | 1525 |
1445 if (JvmtiExport::should_post_compiled_method_load()) { | 1526 if (JvmtiExport::should_post_compiled_method_load()) { |
1446 JvmtiExport::post_compiled_method_load(this); | 1527 JvmtiExport::post_compiled_method_load(this); |
1447 } | 1528 } |
1448 } | 1529 } |
1449 | 1530 |
1531 jmethodID nmethod::get_and_cache_jmethod_id() { | |
1532 if (_jmethod_id == NULL) { | |
1533 // Cache the jmethod_id since it can no longer be looked up once the | |
1534 // method itself has been marked for unloading. | |
1535 _jmethod_id = method()->jmethod_id(); | |
1536 } | |
1537 return _jmethod_id; | |
1538 } | |
1539 | |
1450 void nmethod::post_compiled_method_unload() { | 1540 void nmethod::post_compiled_method_unload() { |
1541 if (unload_reported()) { | |
1542 // During unloading we transition to unloaded and then to zombie | |
1543 // and the unloading is reported during the first transition. | |
1544 return; | |
1545 } | |
1546 | |
1451 assert(_method != NULL && !is_unloaded(), "just checking"); | 1547 assert(_method != NULL && !is_unloaded(), "just checking"); |
1452 DTRACE_METHOD_UNLOAD_PROBE(method()); | 1548 DTRACE_METHOD_UNLOAD_PROBE(method()); |
1453 | 1549 |
1454 // If a JVMTI agent has enabled the CompiledMethodUnload event then | 1550 // If a JVMTI agent has enabled the CompiledMethodUnload event then |
1455 // post the event. Sometime later this nmethod will be made a zombie by | 1551 // post the event. Sometime later this nmethod will be made a zombie |
1456 // the sweeper but the methodOop will not be valid at that point. | 1552 // by the sweeper but the methodOop will not be valid at that point. |
1457 if (JvmtiExport::should_post_compiled_method_unload()) { | 1553 // If the _jmethod_id is null then no load event was ever requested |
1554 // so don't bother posting the unload. The main reason for this is | |
1555 // that the jmethodID is a weak reference to the methodOop so if | |
1556 // it's being unloaded there's no way to look it up since the weak | |
1557 // ref will have been cleared. | |
1558 if (_jmethod_id != NULL && JvmtiExport::should_post_compiled_method_unload()) { | |
1458 assert(!unload_reported(), "already unloaded"); | 1559 assert(!unload_reported(), "already unloaded"); |
1459 HandleMark hm; | 1560 HandleMark hm; |
1460 JvmtiExport::post_compiled_method_unload_at_safepoint( | 1561 JvmtiExport::post_compiled_method_unload(_jmethod_id, insts_begin()); |
1461 method()->jmethod_id(), code_begin()); | |
1462 } | 1562 } |
1463 | 1563 |
1464 // The JVMTI CompiledMethodUnload event can be enabled or disabled at | 1564 // The JVMTI CompiledMethodUnload event can be enabled or disabled at |
1465 // any time. As the nmethod is being unloaded now we mark it has | 1565 // any time. As the nmethod is being unloaded now we mark it has |
1466 // having the unload event reported - this will ensure that we don't | 1566 // having the unload event reported - this will ensure that we don't |
1539 is_alive->do_object_b(cichk_oop->holder_klass())) { | 1639 is_alive->do_object_b(cichk_oop->holder_klass())) { |
1540 continue; | 1640 continue; |
1541 } | 1641 } |
1542 } | 1642 } |
1543 ic->set_to_clean(); | 1643 ic->set_to_clean(); |
1544 assert(ic->cached_oop() == NULL, "cached oop in IC should be cleared") | 1644 assert(ic->cached_oop() == NULL, |
1645 "cached oop in IC should be cleared"); | |
1545 } | 1646 } |
1546 } | 1647 } |
1547 } | 1648 } |
1548 } | 1649 } |
1549 | 1650 |
1748 } | 1849 } |
1749 | 1850 |
1750 // Method that knows how to preserve outgoing arguments at call. This method must be | 1851 // Method that knows how to preserve outgoing arguments at call. This method must be |
1751 // called with a frame corresponding to a Java invoke | 1852 // called with a frame corresponding to a Java invoke |
1752 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { | 1853 void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { |
1854 #ifndef SHARK | |
1753 if (!method()->is_native()) { | 1855 if (!method()->is_native()) { |
1754 SimpleScopeDesc ssd(this, fr.pc()); | 1856 SimpleScopeDesc ssd(this, fr.pc()); |
1755 Bytecode_invoke* call = Bytecode_invoke_at(ssd.method(), ssd.bci()); | 1857 Bytecode_invoke* call = Bytecode_invoke_at(ssd.method(), ssd.bci()); |
1756 bool has_receiver = call->has_receiver(); | 1858 bool has_receiver = call->has_receiver(); |
1757 symbolOop signature = call->signature(); | 1859 symbolOop signature = call->signature(); |
1758 fr.oops_compiled_arguments_do(signature, has_receiver, reg_map, f); | 1860 fr.oops_compiled_arguments_do(signature, has_receiver, reg_map, f); |
1759 } | 1861 } |
1862 #endif // !SHARK | |
1760 } | 1863 } |
1761 | 1864 |
1762 | 1865 |
1763 oop nmethod::embeddedOop_at(u_char* p) { | 1866 oop nmethod::embeddedOop_at(u_char* p) { |
1764 RelocIterator iter(this, p, p + oopSize); | 1867 RelocIterator iter(this, p, p + oopSize); |
1805 memcpy(scopes_pcs_begin(), pcs, size); | 1908 memcpy(scopes_pcs_begin(), pcs, size); |
1806 | 1909 |
1807 // Adjust the final sentinel downward. | 1910 // Adjust the final sentinel downward. |
1808 PcDesc* last_pc = &scopes_pcs_begin()[count-1]; | 1911 PcDesc* last_pc = &scopes_pcs_begin()[count-1]; |
1809 assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity"); | 1912 assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity"); |
1810 last_pc->set_pc_offset(instructions_size() + 1); | 1913 last_pc->set_pc_offset(content_size() + 1); |
1811 for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) { | 1914 for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) { |
1812 // Fill any rounding gaps with copies of the last record. | 1915 // Fill any rounding gaps with copies of the last record. |
1813 last_pc[1] = last_pc[0]; | 1916 last_pc[1] = last_pc[0]; |
1814 } | 1917 } |
1815 // The following assert could fail if sizeof(PcDesc) is not | 1918 // The following assert could fail if sizeof(PcDesc) is not |
1845 #endif | 1948 #endif |
1846 | 1949 |
1847 | 1950 |
1848 // Finds a PcDesc with real-pc equal to "pc" | 1951 // Finds a PcDesc with real-pc equal to "pc" |
1849 PcDesc* nmethod::find_pc_desc_internal(address pc, bool approximate) { | 1952 PcDesc* nmethod::find_pc_desc_internal(address pc, bool approximate) { |
1850 address base_address = instructions_begin(); | 1953 address base_address = code_begin(); |
1851 if ((pc < base_address) || | 1954 if ((pc < base_address) || |
1852 (pc - base_address) >= (ptrdiff_t) PcDesc::upper_offset_limit) { | 1955 (pc - base_address) >= (ptrdiff_t) PcDesc::upper_offset_limit) { |
1853 return NULL; // PC is wildly out of range | 1956 return NULL; // PC is wildly out of range |
1854 } | 1957 } |
1855 int pc_offset = (int) (pc - base_address); | 1958 int pc_offset = (int) (pc - base_address); |
1993 return false; | 2096 return false; |
1994 } | 2097 } |
1995 | 2098 |
1996 | 2099 |
1997 bool nmethod::is_patchable_at(address instr_addr) { | 2100 bool nmethod::is_patchable_at(address instr_addr) { |
1998 assert (code_contains(instr_addr), "wrong nmethod used"); | 2101 assert(insts_contains(instr_addr), "wrong nmethod used"); |
1999 if (is_zombie()) { | 2102 if (is_zombie()) { |
2000 // a zombie may never be patched | 2103 // a zombie may never be patched |
2001 return false; | 2104 return false; |
2002 } | 2105 } |
2003 return true; | 2106 return true; |
2005 | 2108 |
2006 | 2109 |
2007 address nmethod::continuation_for_implicit_exception(address pc) { | 2110 address nmethod::continuation_for_implicit_exception(address pc) { |
2008 // Exception happened outside inline-cache check code => we are inside | 2111 // Exception happened outside inline-cache check code => we are inside |
2009 // an active nmethod => use cpc to determine a return address | 2112 // an active nmethod => use cpc to determine a return address |
2010 int exception_offset = pc - instructions_begin(); | 2113 int exception_offset = pc - code_begin(); |
2011 int cont_offset = ImplicitExceptionTable(this).at( exception_offset ); | 2114 int cont_offset = ImplicitExceptionTable(this).at( exception_offset ); |
2012 #ifdef ASSERT | 2115 #ifdef ASSERT |
2013 if (cont_offset == 0) { | 2116 if (cont_offset == 0) { |
2014 Thread* thread = ThreadLocalStorage::get_thread_slow(); | 2117 Thread* thread = ThreadLocalStorage::get_thread_slow(); |
2015 ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY | 2118 ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY |
2026 #endif | 2129 #endif |
2027 if (cont_offset == 0) { | 2130 if (cont_offset == 0) { |
2028 // Let the normal error handling report the exception | 2131 // Let the normal error handling report the exception |
2029 return NULL; | 2132 return NULL; |
2030 } | 2133 } |
2031 return instructions_begin() + cont_offset; | 2134 return code_begin() + cont_offset; |
2032 } | 2135 } |
2033 | 2136 |
2034 | 2137 |
2035 | 2138 |
2036 void nmethod_init() { | 2139 void nmethod_init() { |
2037 // make sure you didn't forget to adjust the filler fields | 2140 // make sure you didn't forget to adjust the filler fields |
2038 assert(sizeof(nmFlags) <= 4, "nmFlags occupies more than a word"); | |
2039 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word"); | 2141 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word"); |
2040 } | 2142 } |
2041 | 2143 |
2042 | 2144 |
2043 //------------------------------------------------------------------------------------------- | 2145 //------------------------------------------------------------------------------------------- |
2128 assert(method()->is_oop(), "must be valid"); | 2230 assert(method()->is_oop(), "must be valid"); |
2129 | 2231 |
2130 ResourceMark rm; | 2232 ResourceMark rm; |
2131 | 2233 |
2132 if (!CodeCache::contains(this)) { | 2234 if (!CodeCache::contains(this)) { |
2133 fatal1("nmethod at " INTPTR_FORMAT " not in zone", this); | 2235 fatal(err_msg("nmethod at " INTPTR_FORMAT " not in zone", this)); |
2134 } | 2236 } |
2135 | 2237 |
2136 if(is_native_method() ) | 2238 if(is_native_method() ) |
2137 return; | 2239 return; |
2138 | 2240 |
2139 nmethod* nm = CodeCache::find_nmethod(verified_entry_point()); | 2241 nmethod* nm = CodeCache::find_nmethod(verified_entry_point()); |
2140 if (nm != this) { | 2242 if (nm != this) { |
2141 fatal1("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", this); | 2243 fatal(err_msg("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", |
2244 this)); | |
2142 } | 2245 } |
2143 | 2246 |
2144 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { | 2247 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { |
2145 if (! p->verify(this)) { | 2248 if (! p->verify(this)) { |
2146 tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", this); | 2249 tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", this); |
2258 | 2361 |
2259 if (is_compiled_by_c1()) { | 2362 if (is_compiled_by_c1()) { |
2260 tty->print("(c1) "); | 2363 tty->print("(c1) "); |
2261 } else if (is_compiled_by_c2()) { | 2364 } else if (is_compiled_by_c2()) { |
2262 tty->print("(c2) "); | 2365 tty->print("(c2) "); |
2366 } else if (is_compiled_by_shark()) { | |
2367 tty->print("(shark) "); | |
2263 } else { | 2368 } else { |
2264 tty->print("(nm) "); | 2369 tty->print("(nm) "); |
2265 } | 2370 } |
2266 | 2371 |
2267 print_on(tty, "nmethod"); | 2372 print_on(tty, "nmethod"); |
2268 tty->cr(); | 2373 tty->cr(); |
2269 if (WizardMode) { | 2374 if (WizardMode) { |
2270 tty->print("((nmethod*) "INTPTR_FORMAT ") ", this); | 2375 tty->print("((nmethod*) "INTPTR_FORMAT ") ", this); |
2271 tty->print(" for method " INTPTR_FORMAT , (address)method()); | 2376 tty->print(" for method " INTPTR_FORMAT , (address)method()); |
2272 tty->print(" { "); | 2377 tty->print(" { "); |
2273 if (version()) tty->print("v%d ", version()); | |
2274 if (level()) tty->print("l%d ", level()); | |
2275 if (is_in_use()) tty->print("in_use "); | 2378 if (is_in_use()) tty->print("in_use "); |
2276 if (is_not_entrant()) tty->print("not_entrant "); | 2379 if (is_not_entrant()) tty->print("not_entrant "); |
2277 if (is_zombie()) tty->print("zombie "); | 2380 if (is_zombie()) tty->print("zombie "); |
2278 if (is_unloaded()) tty->print("unloaded "); | 2381 if (is_unloaded()) tty->print("unloaded "); |
2279 if (on_scavenge_root_list()) tty->print("scavenge_root "); | 2382 if (on_scavenge_root_list()) tty->print("scavenge_root "); |
2285 size()); | 2388 size()); |
2286 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | 2389 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2287 relocation_begin(), | 2390 relocation_begin(), |
2288 relocation_end(), | 2391 relocation_end(), |
2289 relocation_size()); | 2392 relocation_size()); |
2290 if (code_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | 2393 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2291 code_begin(), | 2394 consts_begin(), |
2292 code_end(), | 2395 consts_end(), |
2293 code_size()); | 2396 consts_size()); |
2397 if (insts_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2398 insts_begin(), | |
2399 insts_end(), | |
2400 insts_size()); | |
2294 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | 2401 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2295 stub_begin(), | 2402 stub_begin(), |
2296 stub_end(), | 2403 stub_end(), |
2297 stub_size()); | 2404 stub_size()); |
2298 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | 2405 if (oops_size () > 0) tty->print_cr(" oops [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2299 consts_begin(), | 2406 oops_begin(), |
2300 consts_end(), | 2407 oops_end(), |
2301 consts_size()); | 2408 oops_size()); |
2302 if (scopes_data_size () > 0) tty->print_cr(" scopes data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | 2409 if (scopes_data_size () > 0) tty->print_cr(" scopes data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2303 scopes_data_begin(), | 2410 scopes_data_begin(), |
2304 scopes_data_end(), | 2411 scopes_data_end(), |
2305 scopes_data_size()); | 2412 scopes_data_size()); |
2306 if (scopes_pcs_size () > 0) tty->print_cr(" scopes pcs [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | 2413 if (scopes_pcs_size () > 0) tty->print_cr(" scopes pcs [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2317 handler_table_size()); | 2424 handler_table_size()); |
2318 if (nul_chk_table_size() > 0) tty->print_cr(" nul chk table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | 2425 if (nul_chk_table_size() > 0) tty->print_cr(" nul chk table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", |
2319 nul_chk_table_begin(), | 2426 nul_chk_table_begin(), |
2320 nul_chk_table_end(), | 2427 nul_chk_table_end(), |
2321 nul_chk_table_size()); | 2428 nul_chk_table_size()); |
2322 if (oops_size () > 0) tty->print_cr(" oops [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", | |
2323 oops_begin(), | |
2324 oops_end(), | |
2325 oops_size()); | |
2326 } | 2429 } |
2327 | 2430 |
2328 void nmethod::print_code() { | 2431 void nmethod::print_code() { |
2329 HandleMark hm; | 2432 HandleMark hm; |
2330 ResourceMark m; | 2433 ResourceMark m; |
2450 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]"); | 2553 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]"); |
2451 if (block_begin == exception_begin()) stream->print_cr("[Exception Handler]"); | 2554 if (block_begin == exception_begin()) stream->print_cr("[Exception Handler]"); |
2452 if (block_begin == unwind_handler_begin()) stream->print_cr("[Unwind Handler]"); | 2555 if (block_begin == unwind_handler_begin()) stream->print_cr("[Unwind Handler]"); |
2453 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]"); | 2556 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]"); |
2454 if (block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]"); | 2557 if (block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]"); |
2455 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]"); | 2558 |
2559 if (has_method_handle_invokes()) | |
2560 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]"); | |
2561 | |
2456 if (block_begin == consts_begin()) stream->print_cr("[Constants]"); | 2562 if (block_begin == consts_begin()) stream->print_cr("[Constants]"); |
2563 | |
2457 if (block_begin == entry_point()) { | 2564 if (block_begin == entry_point()) { |
2458 methodHandle m = method(); | 2565 methodHandle m = method(); |
2459 if (m.not_null()) { | 2566 if (m.not_null()) { |
2460 stream->print(" # "); | 2567 stream->print(" # "); |
2461 m->print_value_on(stream); | 2568 m->print_value_on(stream); |
2551 | 2658 |
2552 void nmethod::print_code_comment_on(outputStream* st, int column, u_char* begin, u_char* end) { | 2659 void nmethod::print_code_comment_on(outputStream* st, int column, u_char* begin, u_char* end) { |
2553 // First, find an oopmap in (begin, end]. | 2660 // First, find an oopmap in (begin, end]. |
2554 // We use the odd half-closed interval so that oop maps and scope descs | 2661 // We use the odd half-closed interval so that oop maps and scope descs |
2555 // which are tied to the byte after a call are printed with the call itself. | 2662 // which are tied to the byte after a call are printed with the call itself. |
2556 address base = instructions_begin(); | 2663 address base = code_begin(); |
2557 OopMapSet* oms = oop_maps(); | 2664 OopMapSet* oms = oop_maps(); |
2558 if (oms != NULL) { | 2665 if (oms != NULL) { |
2559 for (int i = 0, imax = oms->size(); i < imax; i++) { | 2666 for (int i = 0, imax = oms->size(); i < imax; i++) { |
2560 OopMap* om = oms->at(i); | 2667 OopMap* om = oms->at(i); |
2561 address pc = base + om->offset(); | 2668 address pc = base + om->offset(); |
2602 case Bytecodes::_getfield: | 2709 case Bytecodes::_getfield: |
2603 case Bytecodes::_putfield: | 2710 case Bytecodes::_putfield: |
2604 case Bytecodes::_getstatic: | 2711 case Bytecodes::_getstatic: |
2605 case Bytecodes::_putstatic: | 2712 case Bytecodes::_putstatic: |
2606 { | 2713 { |
2607 methodHandle sdm = sd->method(); | 2714 Bytecode_field* field = Bytecode_field_at(sd->method(), sd->bci()); |
2608 Bytecode_field* field = Bytecode_field_at(sdm(), sdm->bcp_from(sd->bci())); | |
2609 constantPoolOop sdmc = sdm->constants(); | |
2610 symbolOop name = sdmc->name_ref_at(field->index()); | |
2611 st->print(" "); | 2715 st->print(" "); |
2612 if (name != NULL) | 2716 if (field->name() != NULL) |
2613 name->print_symbol_on(st); | 2717 field->name()->print_symbol_on(st); |
2614 else | 2718 else |
2615 st->print("<UNKNOWN>"); | 2719 st->print("<UNKNOWN>"); |
2616 } | 2720 } |
2617 } | 2721 } |
2618 } | 2722 } |
2642 if (str != NULL) { | 2746 if (str != NULL) { |
2643 if (sd != NULL) st->cr(); | 2747 if (sd != NULL) st->cr(); |
2644 st->move_to(column); | 2748 st->move_to(column); |
2645 st->print("; {%s}", str); | 2749 st->print("; {%s}", str); |
2646 } | 2750 } |
2647 int cont_offset = ImplicitExceptionTable(this).at(begin - instructions_begin()); | 2751 int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin()); |
2648 if (cont_offset != 0) { | 2752 if (cont_offset != 0) { |
2649 st->move_to(column); | 2753 st->move_to(column); |
2650 st->print("; implicit exception: dispatches to " INTPTR_FORMAT, instructions_begin() + cont_offset); | 2754 st->print("; implicit exception: dispatches to " INTPTR_FORMAT, code_begin() + cont_offset); |
2651 } | 2755 } |
2652 | 2756 |
2653 } | 2757 } |
2654 | 2758 |
2655 #ifndef PRODUCT | 2759 #ifndef PRODUCT |
2679 void nmethod::print_handler_table() { | 2783 void nmethod::print_handler_table() { |
2680 ExceptionHandlerTable(this).print(); | 2784 ExceptionHandlerTable(this).print(); |
2681 } | 2785 } |
2682 | 2786 |
2683 void nmethod::print_nul_chk_table() { | 2787 void nmethod::print_nul_chk_table() { |
2684 ImplicitExceptionTable(this).print(instructions_begin()); | 2788 ImplicitExceptionTable(this).print(code_begin()); |
2685 } | 2789 } |
2686 | 2790 |
2687 void nmethod::print_statistics() { | 2791 void nmethod::print_statistics() { |
2688 ttyLocker ttyl; | 2792 ttyLocker ttyl; |
2689 if (xtty != NULL) xtty->head("statistics type='nmethod'"); | 2793 if (xtty != NULL) xtty->head("statistics type='nmethod'"); |