14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/codeCache.hpp"
27 #include "code/compiledIC.hpp"
28 #include "code/dependencies.hpp"
29 #include "code/nmethod.hpp"
30 #include "code/scopeDesc.hpp"
31 #include "compiler/abstractCompiler.hpp"
32 #include "compiler/compileBroker.hpp"
33 #include "compiler/compileLog.hpp"
34 #include "compiler/compilerOracle.hpp"
35 #include "compiler/disassembler.hpp"
36 #include "interpreter/bytecode.hpp"
37 #include "oops/methodData.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "prims/jvmtiRedefineClassesTrace.hpp"
40 #include "prims/jvmtiImpl.hpp"
41 #include "runtime/atomic.inline.hpp"
42 #include "runtime/orderAccess.inline.hpp"
43 #include "runtime/sharedRuntime.hpp"
44 #include "runtime/sweeper.hpp"
45 #include "utilities/resourceHash.hpp"
46 #include "utilities/dtrace.hpp"
47 #include "utilities/events.hpp"
48 #include "utilities/xmlstream.hpp"
49 #ifdef SHARK
50 #include "shark/sharkCompiler.hpp"
51 #endif
52
53 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
54
487 int frame_complete,
488 int frame_size,
489 ByteSize basic_lock_owner_sp_offset,
490 ByteSize basic_lock_sp_offset,
491 OopMapSet* oop_maps) {
492 code_buffer->finalize_oop_references(method);
493 // create nmethod
494 nmethod* nm = NULL;
495 {
496 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
497 int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
498 CodeOffsets offsets;
499 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
500 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
501 nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), native_nmethod_size,
502 compile_id, &offsets,
503 code_buffer, frame_size,
504 basic_lock_owner_sp_offset,
505 basic_lock_sp_offset, oop_maps);
506 NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_native_nmethod(nm));
507 if ((PrintAssembly || CompilerOracle::should_print(method)) && nm != NULL) {
508 Disassembler::decode(nm);
509 }
510 }
511 // verify nmethod
512 debug_only(if (nm) nm->verify();) // might block
513
514 if (nm != NULL) {
515 nm->log_new_nmethod();
516 }
517
518 return nm;
519 }
520
521 nmethod* nmethod::new_nmethod(methodHandle method,
522 int compile_id,
523 int entry_bci,
524 CodeOffsets* offsets,
525 int orig_pc_offset,
526 DebugInformationRecorder* debug_info,
527 Dependencies* dependencies,
528 CodeBuffer* code_buffer, int frame_size,
529 OopMapSet* oop_maps,
562 // class hierarchy above the loaded class, checking only nmethods
563 // which are dependent on those classes. The slow way is to
564 // check every nmethod for dependencies which makes it linear in
565 // the number of methods compiled. For applications with a lot
566 // classes the slow way is too slow.
567 for (Dependencies::DepStream deps(nm); deps.next(); ) {
568 if (deps.type() == Dependencies::call_site_target_value) {
569 // CallSite dependencies are managed on per-CallSite instance basis.
570 oop call_site = deps.argument_oop(0);
571 MethodHandles::add_dependent_nmethod(call_site, nm);
572 } else {
573 Klass* klass = deps.context_type();
574 if (klass == NULL) {
575 continue; // ignore things like evol_method
576 }
577 // record this nmethod as dependent on this klass
578 InstanceKlass::cast(klass)->add_dependent_nmethod(nm);
579 }
580 }
581 NOT_PRODUCT(nmethod_stats.note_nmethod(nm));
582 if (PrintAssembly || CompilerOracle::has_option_string(method, "PrintAssembly")) {
583 Disassembler::decode(nm);
584 }
585 }
586 }
587 // Do verification and logging outside CodeCache_lock.
588 if (nm != NULL) {
589 // Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet.
590 DEBUG_ONLY(nm->verify();)
591 nm->log_new_nmethod();
592 }
593 return nm;
594 }
595
596
597 // For native wrappers
598 nmethod::nmethod(
599 Method* method,
600 int nmethod_size,
601 int compile_id,
602 CodeOffsets* offsets,
603 CodeBuffer* code_buffer,
604 int frame_size,
766 if (ScavengeRootsInCode) {
767 if (detect_scavenge_root_oops()) {
768 CodeCache::add_scavenge_root_nmethod(this);
769 }
770 Universe::heap()->register_nmethod(this);
771 }
772 debug_only(verify_scavenge_root_oops());
773
774 CodeCache::commit(this);
775
776 // Copy contents of ExceptionHandlerTable to nmethod
777 handler_table->copy_to(this);
778 nul_chk_table->copy_to(this);
779
780 // we use the information of entry points to find out if a method is
781 // static or non static
782 assert(compiler->is_c2() ||
783 _method->is_static() == (entry_point() == _verified_entry_point),
784 " entry points must be same for static methods and vice versa");
785 }
786
787 bool printnmethods = PrintNMethods
788 || CompilerOracle::should_print(_method)
789 || CompilerOracle::has_option_string(_method, "PrintNMethods");
790 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
791 print_nmethod(printnmethods);
792 }
793 }
794
795
796 // Print a short set of xml attributes to identify this nmethod. The
797 // output should be embedded in some other element.
798 void nmethod::log_identity(xmlStream* log) const {
799 log->print(" compile_id='%d'", compile_id());
800 const char* nm_kind = compile_kind();
801 if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind);
802 if (compiler() != NULL) {
803 log->print(" compiler='%s'", compiler()->name());
804 }
805 if (TieredCompilation) {
806 log->print(" level='%d'", comp_level());
807 }
808 }
809
810
811 #define LOG_OFFSET(log, name) \
812 if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \
813 log->print(" " XSTR(name) "_offset='%d'" , \
814 (intptr_t)name##_begin() - (intptr_t)this)
|
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/codeCache.hpp"
27 #include "code/compiledIC.hpp"
28 #include "code/dependencies.hpp"
29 #include "code/nmethod.hpp"
30 #include "code/scopeDesc.hpp"
31 #include "compiler/abstractCompiler.hpp"
32 #include "compiler/compileBroker.hpp"
33 #include "compiler/compileLog.hpp"
34 #include "compiler/compilerDirectives.hpp"
35 #include "compiler/disassembler.hpp"
36 #include "interpreter/bytecode.hpp"
37 #include "oops/methodData.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "prims/jvmtiRedefineClassesTrace.hpp"
40 #include "prims/jvmtiImpl.hpp"
41 #include "runtime/atomic.inline.hpp"
42 #include "runtime/orderAccess.inline.hpp"
43 #include "runtime/sharedRuntime.hpp"
44 #include "runtime/sweeper.hpp"
45 #include "utilities/resourceHash.hpp"
46 #include "utilities/dtrace.hpp"
47 #include "utilities/events.hpp"
48 #include "utilities/xmlstream.hpp"
49 #ifdef SHARK
50 #include "shark/sharkCompiler.hpp"
51 #endif
52
53 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
54
487 int frame_complete,
488 int frame_size,
489 ByteSize basic_lock_owner_sp_offset,
490 ByteSize basic_lock_sp_offset,
491 OopMapSet* oop_maps) {
492 code_buffer->finalize_oop_references(method);
493 // create nmethod
494 nmethod* nm = NULL;
495 {
496 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
497 int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
498 CodeOffsets offsets;
499 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
500 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
501 nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), native_nmethod_size,
502 compile_id, &offsets,
503 code_buffer, frame_size,
504 basic_lock_owner_sp_offset,
505 basic_lock_sp_offset, oop_maps);
506 NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_native_nmethod(nm));
507 }
508 // verify nmethod
509 debug_only(if (nm) nm->verify();) // might block
510
511 if (nm != NULL) {
512 nm->log_new_nmethod();
513 }
514
515 return nm;
516 }
517
518 nmethod* nmethod::new_nmethod(methodHandle method,
519 int compile_id,
520 int entry_bci,
521 CodeOffsets* offsets,
522 int orig_pc_offset,
523 DebugInformationRecorder* debug_info,
524 Dependencies* dependencies,
525 CodeBuffer* code_buffer, int frame_size,
526 OopMapSet* oop_maps,
559 // class hierarchy above the loaded class, checking only nmethods
560 // which are dependent on those classes. The slow way is to
561 // check every nmethod for dependencies which makes it linear in
562 // the number of methods compiled. For applications with a lot
563 // classes the slow way is too slow.
564 for (Dependencies::DepStream deps(nm); deps.next(); ) {
565 if (deps.type() == Dependencies::call_site_target_value) {
566 // CallSite dependencies are managed on per-CallSite instance basis.
567 oop call_site = deps.argument_oop(0);
568 MethodHandles::add_dependent_nmethod(call_site, nm);
569 } else {
570 Klass* klass = deps.context_type();
571 if (klass == NULL) {
572 continue; // ignore things like evol_method
573 }
574 // record this nmethod as dependent on this klass
575 InstanceKlass::cast(klass)->add_dependent_nmethod(nm);
576 }
577 }
578 NOT_PRODUCT(nmethod_stats.note_nmethod(nm));
579 }
580 }
581 // Do verification and logging outside CodeCache_lock.
582 if (nm != NULL) {
583 // Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet.
584 DEBUG_ONLY(nm->verify();)
585 nm->log_new_nmethod();
586 }
587 return nm;
588 }
589
590
591 // For native wrappers
592 nmethod::nmethod(
593 Method* method,
594 int nmethod_size,
595 int compile_id,
596 CodeOffsets* offsets,
597 CodeBuffer* code_buffer,
598 int frame_size,
760 if (ScavengeRootsInCode) {
761 if (detect_scavenge_root_oops()) {
762 CodeCache::add_scavenge_root_nmethod(this);
763 }
764 Universe::heap()->register_nmethod(this);
765 }
766 debug_only(verify_scavenge_root_oops());
767
768 CodeCache::commit(this);
769
770 // Copy contents of ExceptionHandlerTable to nmethod
771 handler_table->copy_to(this);
772 nul_chk_table->copy_to(this);
773
774 // we use the information of entry points to find out if a method is
775 // static or non static
776 assert(compiler->is_c2() ||
777 _method->is_static() == (entry_point() == _verified_entry_point),
778 " entry points must be same for static methods and vice versa");
779 }
780 }
781
782 // Print a short set of xml attributes to identify this nmethod. The
783 // output should be embedded in some other element.
784 void nmethod::log_identity(xmlStream* log) const {
785 log->print(" compile_id='%d'", compile_id());
786 const char* nm_kind = compile_kind();
787 if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind);
788 if (compiler() != NULL) {
789 log->print(" compiler='%s'", compiler()->name());
790 }
791 if (TieredCompilation) {
792 log->print(" level='%d'", comp_level());
793 }
794 }
795
796
797 #define LOG_OFFSET(log, name) \
798 if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \
799 log->print(" " XSTR(name) "_offset='%d'" , \
800 (intptr_t)name##_begin() - (intptr_t)this)
|