454 bool oops_do_try_claim_weak_request();
455
456 // Attempt Unclaimed -> N|SD transition. Returns the current link.
457 oops_do_mark_link* oops_do_try_claim_strong_done();
458 // Attempt N|WR -> X|WD transition. Returns nullptr if successful, X otherwise.
459 nmethod* oops_do_try_add_to_list_as_weak_done();
460
461 // Attempt X|WD -> N|SR transition. Returns the current link.
462 oops_do_mark_link* oops_do_try_add_strong_request(oops_do_mark_link* next);
463 // Attempt X|WD -> X|SD transition. Returns true if successful.
464 bool oops_do_try_claim_weak_done_as_strong_done(oops_do_mark_link* next);
465
466 // Do the N|SD -> X|SD transition.
467 void oops_do_add_to_list_as_strong_done();
468
469 // Sets this nmethod as strongly claimed (as part of N|SD -> X|SD and N|SR -> X|SD
470 // transitions).
471 void oops_do_set_strong_done(nmethod* old_head);
472
473 public:
474 // create nmethod with entry_bci
475 static nmethod* new_nmethod(const methodHandle& method,
476 int compile_id,
477 int entry_bci,
478 CodeOffsets* offsets,
479 int orig_pc_offset,
480 DebugInformationRecorder* recorder,
481 Dependencies* dependencies,
482 CodeBuffer *code_buffer,
483 int frame_size,
484 OopMapSet* oop_maps,
485 ExceptionHandlerTable* handler_table,
486 ImplicitExceptionTable* nul_chk_table,
487 AbstractCompiler* compiler,
488 CompLevel comp_level
489 #if INCLUDE_JVMCI
490 , char* speculations = nullptr,
491 int speculations_len = 0,
492 JVMCINMethodData* jvmci_data = nullptr
493 #endif
616
617 // flag accessing and manipulation
618 bool is_not_installed() const { return _state == not_installed; }
619 bool is_in_use() const { return _state <= in_use; }
620 bool is_not_entrant() const { return _state == not_entrant; }
621 int get_state() const { return _state; }
622
623 void clear_unloading_state();
624 // Heuristically deduce an nmethod isn't worth keeping around
625 bool is_cold();
626 bool is_unloading();
627 void do_unloading(bool unloading_occurred);
628
629 bool make_in_use() {
630 return try_transition(in_use);
631 }
632 // Make the nmethod non entrant. The nmethod will continue to be
633 // alive. It is used when an uncommon trap happens. Returns true
634 // if this thread changed the state of the nmethod or false if
635 // another thread performed the transition.
636 bool make_not_entrant(const char* reason);
637 bool make_not_used() { return make_not_entrant("not used"); }
638
639 bool is_marked_for_deoptimization() const { return deoptimization_status() != not_marked; }
640 bool has_been_deoptimized() const { return deoptimization_status() == deoptimize_done; }
641 void set_deoptimized_done();
642
643 bool update_recompile_counts() const {
644 // Update recompile counts when either the update is explicitly requested (deoptimize)
645 // or the nmethod is not marked for deoptimization at all (not_marked).
646 // The latter happens during uncommon traps when deoptimized nmethod is made not entrant.
647 DeoptimizationStatus status = deoptimization_status();
648 return status != deoptimize_noupdate && status != deoptimize_done;
649 }
650
651 // tells whether frames described by this nmethod can be deoptimized
652 // note: native wrappers cannot be deoptimized.
653 bool can_be_deoptimized() const { return is_java_method(); }
654
655 bool has_dependencies() { return dependencies_size() != 0; }
656 void print_dependencies_on(outputStream* out) PRODUCT_RETURN;
657 void flush_dependencies();
930 void print_recorded_oops();
931 void print_recorded_metadata();
932
933 void print_oops(outputStream* st); // oops from the underlying CodeBlob.
934 void print_metadata(outputStream* st); // metadata in metadata pool.
935 #else
936 void print_pcs_on(outputStream* st) { return; }
937 #endif
938
939 void print_calls(outputStream* st) PRODUCT_RETURN;
940 static void print_statistics() PRODUCT_RETURN;
941
942 void maybe_print_nmethod(const DirectiveSet* directive);
943 void print_nmethod(bool print_code);
944
945 void print_on_with_msg(outputStream* st, const char* msg) const;
946
947 // Logging
948 void log_identity(xmlStream* log) const;
949 void log_new_nmethod() const;
950 void log_state_change(const char* reason) const;
951
952 // Prints block-level comments, including nmethod specific block labels:
953 void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;
954 const char* nmethod_section_label(address pos) const;
955
956 // returns whether this nmethod has code comments.
957 bool has_code_comment(address begin, address end);
958 // Prints a comment for one native instruction (reloc info, pc desc)
959 void print_code_comment_on(outputStream* st, int column, address begin, address end);
960
961 // tells if this compiled method is dependent on the given changes,
962 // and the changes have invalidated it
963 bool check_dependency_on(DepChange& changes);
964
965 // Fast breakpoint support. Tells if this compiled method is
966 // dependent on the given method. Returns true if this nmethod
967 // corresponds to the given method as well.
968 bool is_dependent_on_method(Method* dependee);
969
970 // JVMTI's GetLocalInstance() support
|
454 bool oops_do_try_claim_weak_request();
455
456 // Attempt Unclaimed -> N|SD transition. Returns the current link.
457 oops_do_mark_link* oops_do_try_claim_strong_done();
458 // Attempt N|WR -> X|WD transition. Returns nullptr if successful, X otherwise.
459 nmethod* oops_do_try_add_to_list_as_weak_done();
460
461 // Attempt X|WD -> N|SR transition. Returns the current link.
462 oops_do_mark_link* oops_do_try_add_strong_request(oops_do_mark_link* next);
463 // Attempt X|WD -> X|SD transition. Returns true if successful.
464 bool oops_do_try_claim_weak_done_as_strong_done(oops_do_mark_link* next);
465
466 // Do the N|SD -> X|SD transition.
467 void oops_do_add_to_list_as_strong_done();
468
469 // Sets this nmethod as strongly claimed (as part of N|SD -> X|SD and N|SR -> X|SD
470 // transitions).
471 void oops_do_set_strong_done(nmethod* old_head);
472
473 public:
474 // If you change anything in this enum please patch
475 // vmStructs_jvmci.cpp accordingly.
476 enum class InvalidationReason : s1 {
477 NOT_INVALIDATED = -1,
478 C1_CODEPATCH,
479 C1_DEOPTIMIZE,
480 C1_DEOPTIMIZE_FOR_PATCHING,
481 C1_PREDICATE_FAILED_TRAP,
482 CI_REPLAY,
483 UNLOADING,
484 UNLOADING_COLD,
485 JVMCI_INVALIDATE,
486 JVMCI_MATERIALIZE_VIRTUAL_OBJECT,
487 JVMCI_REPLACED_WITH_NEW_CODE,
488 JVMCI_REPROFILE,
489 MARKED_FOR_DEOPTIMIZATION,
490 MISSING_EXCEPTION_HANDLER,
491 NOT_USED,
492 OSR_INVALIDATION_BACK_BRANCH,
493 OSR_INVALIDATION_FOR_COMPILING_WITH_C1,
494 OSR_INVALIDATION_OF_LOWER_LEVEL,
495 SET_NATIVE_FUNCTION,
496 UNCOMMON_TRAP,
497 WHITEBOX_DEOPTIMIZATION,
498 ZOMBIE,
499 INVALIDATION_REASONS_COUNT
500 };
501
502
503 static const char* invalidation_reason_to_string(InvalidationReason invalidation_reason) {
504 switch (invalidation_reason) {
505 case InvalidationReason::C1_CODEPATCH:
506 return "C1 code patch";
507 case InvalidationReason::C1_DEOPTIMIZE:
508 return "C1 deoptimized";
509 case InvalidationReason::C1_DEOPTIMIZE_FOR_PATCHING:
510 return "C1 deoptimize for patching";
511 case InvalidationReason::C1_PREDICATE_FAILED_TRAP:
512 return "C1 predicate failed trap";
513 case InvalidationReason::CI_REPLAY:
514 return "CI replay";
515 case InvalidationReason::JVMCI_INVALIDATE:
516 return "JVMCI invalidate";
517 case InvalidationReason::JVMCI_MATERIALIZE_VIRTUAL_OBJECT:
518 return "JVMCI materialize virtual object";
519 case InvalidationReason::JVMCI_REPLACED_WITH_NEW_CODE:
520 return "JVMCI replaced with new code";
521 case InvalidationReason::JVMCI_REPROFILE:
522 return "JVMCI reprofile";
523 case InvalidationReason::MARKED_FOR_DEOPTIMIZATION:
524 return "marked for deoptimization";
525 case InvalidationReason::MISSING_EXCEPTION_HANDLER:
526 return "missing exception handler";
527 case InvalidationReason::NOT_USED:
528 return "not used";
529 case InvalidationReason::OSR_INVALIDATION_BACK_BRANCH:
530 return "OSR invalidation back branch";
531 case InvalidationReason::OSR_INVALIDATION_FOR_COMPILING_WITH_C1:
532 return "OSR invalidation for compiling with C1";
533 case InvalidationReason::OSR_INVALIDATION_OF_LOWER_LEVEL:
534 return "OSR invalidation of lower level";
535 case InvalidationReason::SET_NATIVE_FUNCTION:
536 return "set native function";
537 case InvalidationReason::UNCOMMON_TRAP:
538 return "uncommon trap";
539 case InvalidationReason::WHITEBOX_DEOPTIMIZATION:
540 return "whitebox deoptimization";
541 case InvalidationReason::ZOMBIE:
542 return "zombie";
543 default: {
544 assert(false, "Unhandled reason");
545 return "Unknown";
546 }
547 }
548 }
549
550 // create nmethod with entry_bci
551 static nmethod* new_nmethod(const methodHandle& method,
552 int compile_id,
553 int entry_bci,
554 CodeOffsets* offsets,
555 int orig_pc_offset,
556 DebugInformationRecorder* recorder,
557 Dependencies* dependencies,
558 CodeBuffer *code_buffer,
559 int frame_size,
560 OopMapSet* oop_maps,
561 ExceptionHandlerTable* handler_table,
562 ImplicitExceptionTable* nul_chk_table,
563 AbstractCompiler* compiler,
564 CompLevel comp_level
565 #if INCLUDE_JVMCI
566 , char* speculations = nullptr,
567 int speculations_len = 0,
568 JVMCINMethodData* jvmci_data = nullptr
569 #endif
692
693 // flag accessing and manipulation
694 bool is_not_installed() const { return _state == not_installed; }
695 bool is_in_use() const { return _state <= in_use; }
696 bool is_not_entrant() const { return _state == not_entrant; }
697 int get_state() const { return _state; }
698
699 void clear_unloading_state();
700 // Heuristically deduce an nmethod isn't worth keeping around
701 bool is_cold();
702 bool is_unloading();
703 void do_unloading(bool unloading_occurred);
704
705 bool make_in_use() {
706 return try_transition(in_use);
707 }
708 // Make the nmethod non entrant. The nmethod will continue to be
709 // alive. It is used when an uncommon trap happens. Returns true
710 // if this thread changed the state of the nmethod or false if
711 // another thread performed the transition.
712 bool make_not_entrant(InvalidationReason invalidation_reason);
713 bool make_not_used() { return make_not_entrant(InvalidationReason::NOT_USED); }
714
715 bool is_marked_for_deoptimization() const { return deoptimization_status() != not_marked; }
716 bool has_been_deoptimized() const { return deoptimization_status() == deoptimize_done; }
717 void set_deoptimized_done();
718
719 bool update_recompile_counts() const {
720 // Update recompile counts when either the update is explicitly requested (deoptimize)
721 // or the nmethod is not marked for deoptimization at all (not_marked).
722 // The latter happens during uncommon traps when deoptimized nmethod is made not entrant.
723 DeoptimizationStatus status = deoptimization_status();
724 return status != deoptimize_noupdate && status != deoptimize_done;
725 }
726
727 // tells whether frames described by this nmethod can be deoptimized
728 // note: native wrappers cannot be deoptimized.
729 bool can_be_deoptimized() const { return is_java_method(); }
730
731 bool has_dependencies() { return dependencies_size() != 0; }
732 void print_dependencies_on(outputStream* out) PRODUCT_RETURN;
733 void flush_dependencies();
1006 void print_recorded_oops();
1007 void print_recorded_metadata();
1008
1009 void print_oops(outputStream* st); // oops from the underlying CodeBlob.
1010 void print_metadata(outputStream* st); // metadata in metadata pool.
1011 #else
1012 void print_pcs_on(outputStream* st) { return; }
1013 #endif
1014
1015 void print_calls(outputStream* st) PRODUCT_RETURN;
1016 static void print_statistics() PRODUCT_RETURN;
1017
1018 void maybe_print_nmethod(const DirectiveSet* directive);
1019 void print_nmethod(bool print_code);
1020
1021 void print_on_with_msg(outputStream* st, const char* msg) const;
1022
1023 // Logging
1024 void log_identity(xmlStream* log) const;
1025 void log_new_nmethod() const;
1026 void log_state_change(InvalidationReason invalidation_reason) const;
1027
1028 // Prints block-level comments, including nmethod specific block labels:
1029 void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;
1030 const char* nmethod_section_label(address pos) const;
1031
1032 // returns whether this nmethod has code comments.
1033 bool has_code_comment(address begin, address end);
1034 // Prints a comment for one native instruction (reloc info, pc desc)
1035 void print_code_comment_on(outputStream* st, int column, address begin, address end);
1036
1037 // tells if this compiled method is dependent on the given changes,
1038 // and the changes have invalidated it
1039 bool check_dependency_on(DepChange& changes);
1040
1041 // Fast breakpoint support. Tells if this compiled method is
1042 // dependent on the given method. Returns true if this nmethod
1043 // corresponds to the given method as well.
1044 bool is_dependent_on_method(Method* dependee);
1045
1046 // JVMTI's GetLocalInstance() support
|