500 void JvmtiCurrentBreakpoints::metadata_do(void f(Metadata*)) {
501 if (_jvmti_breakpoints != NULL) {
502 _jvmti_breakpoints->metadata_do(f);
503 }
504 }
505
506 ///////////////////////////////////////////////////////////////
507 //
508 // class VM_GetOrSetLocal
509 //
510
511 // Constructor for non-object getter
512 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type)
513 : _thread(thread)
514 , _calling_thread(NULL)
515 , _depth(depth)
516 , _index(index)
517 , _type(type)
518 , _jvf(NULL)
519 , _set(false)
520 , _result(JVMTI_ERROR_NONE)
521 {
522 }
523
524 // Constructor for object or non-object setter
525 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value)
526 : _thread(thread)
527 , _calling_thread(NULL)
528 , _depth(depth)
529 , _index(index)
530 , _type(type)
531 , _value(value)
532 , _jvf(NULL)
533 , _set(true)
534 , _result(JVMTI_ERROR_NONE)
535 {
536 }
537
538 // Constructor for object getter
539 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth, int index)
540 : _thread(thread)
541 , _calling_thread(calling_thread)
542 , _depth(depth)
543 , _index(index)
544 , _type(T_OBJECT)
545 , _jvf(NULL)
546 , _set(false)
547 , _result(JVMTI_ERROR_NONE)
548 {
549 }
550
551 vframe *VM_GetOrSetLocal::get_vframe() {
552 if (!_thread->has_last_Java_frame()) {
553 return NULL;
554 }
555 RegisterMap reg_map(_thread);
556 vframe *vf = _thread->last_java_vframe(®_map);
557 int d = 0;
558 while ((vf != NULL) && (d < _depth)) {
559 vf = vf->java_sender();
560 d++;
561 }
562 return vf;
563 }
564
565 javaVFrame *VM_GetOrSetLocal::get_java_vframe() {
566 vframe* vf = get_vframe();
701 return false;
702 }
703 if (extra_slot) {
704 BasicType extra_slot_type = locals->at(_index + 1)->type();
705 if (extra_slot_type != T_INT) {
706 _result = JVMTI_ERROR_INVALID_SLOT;
707 return false;
708 }
709 }
710 if (_type != slot_type && (_type == T_OBJECT || slot_type != T_INT)) {
711 _result = JVMTI_ERROR_TYPE_MISMATCH;
712 return false;
713 }
714 return true;
715 }
716
717 static bool can_be_deoptimized(vframe* vf) {
718 return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized());
719 }
720
721 bool VM_GetOrSetLocal::doit_prologue() {
722 _jvf = get_java_vframe();
723 NULL_CHECK(_jvf, false);
724
725 Method* method_oop = _jvf->method();
726 if (method_oop->is_native()) {
727 if (getting_receiver() && !method_oop->is_static()) {
728 return true;
729 } else {
730 _result = JVMTI_ERROR_OPAQUE_FRAME;
731 return false;
732 }
733 }
734
735 if (!check_slot_type_no_lvt(_jvf)) {
736 return false;
737 }
738 if (method_oop->has_localvariable_table()) {
739 return check_slot_type_lvt(_jvf);
740 }
741 return true;
742 }
743
744 void VM_GetOrSetLocal::doit() {
745 InterpreterOopMap oop_mask;
746 _jvf->method()->mask_for(_jvf->bci(), &oop_mask);
747 if (oop_mask.is_dead(_index)) {
748 // The local can be invalid and uninitialized in the scope of current bci
749 _result = JVMTI_ERROR_INVALID_SLOT;
750 return;
751 }
752 if (_set) {
753 // Force deoptimization of frame if compiled because it's
754 // possible the compiler emitted some locals as constant values,
755 // meaning they are not mutable.
756 if (can_be_deoptimized(_jvf)) {
757
758 // Schedule deoptimization so that eventually the local
759 // update will be written to an interpreter frame.
760 Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
|
500 void JvmtiCurrentBreakpoints::metadata_do(void f(Metadata*)) {
501 if (_jvmti_breakpoints != NULL) {
502 _jvmti_breakpoints->metadata_do(f);
503 }
504 }
505
506 ///////////////////////////////////////////////////////////////
507 //
508 // class VM_GetOrSetLocal
509 //
510
511 // Constructor for non-object getter
512 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type)
513 : _thread(thread)
514 , _calling_thread(NULL)
515 , _depth(depth)
516 , _index(index)
517 , _type(type)
518 , _jvf(NULL)
519 , _set(false)
520 , _eb(NULL, NULL, false) // no references escape
521 , _result(JVMTI_ERROR_NONE)
522 {
523 }
524
525 // Constructor for object or non-object setter
526 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value)
527 : _thread(thread)
528 , _calling_thread(NULL)
529 , _depth(depth)
530 , _index(index)
531 , _type(type)
532 , _value(value)
533 , _jvf(NULL)
534 , _set(true)
535 , _eb(JavaThread::current(), thread, type == T_OBJECT)
536 , _result(JVMTI_ERROR_NONE)
537 {
538 }
539
540 // Constructor for object getter
541 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth, int index)
542 : _thread(thread)
543 , _calling_thread(calling_thread)
544 , _depth(depth)
545 , _index(index)
546 , _type(T_OBJECT)
547 , _jvf(NULL)
548 , _set(false)
549 , _eb(calling_thread, thread, true)
550 , _result(JVMTI_ERROR_NONE)
551 {
552 }
553
554 vframe *VM_GetOrSetLocal::get_vframe() {
555 if (!_thread->has_last_Java_frame()) {
556 return NULL;
557 }
558 RegisterMap reg_map(_thread);
559 vframe *vf = _thread->last_java_vframe(®_map);
560 int d = 0;
561 while ((vf != NULL) && (d < _depth)) {
562 vf = vf->java_sender();
563 d++;
564 }
565 return vf;
566 }
567
568 javaVFrame *VM_GetOrSetLocal::get_java_vframe() {
569 vframe* vf = get_vframe();
704 return false;
705 }
706 if (extra_slot) {
707 BasicType extra_slot_type = locals->at(_index + 1)->type();
708 if (extra_slot_type != T_INT) {
709 _result = JVMTI_ERROR_INVALID_SLOT;
710 return false;
711 }
712 }
713 if (_type != slot_type && (_type == T_OBJECT || slot_type != T_INT)) {
714 _result = JVMTI_ERROR_TYPE_MISMATCH;
715 return false;
716 }
717 return true;
718 }
719
720 static bool can_be_deoptimized(vframe* vf) {
721 return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized());
722 }
723
724 // Revert optimizations based on escape analysis if this is an access to a local object
725 bool VM_GetOrSetLocal::deoptimize_objects(javaVFrame* jvf) {
726 #if COMPILER2_OR_JVMCI
727 if (NOT_JVMCI(DoEscapeAnalysis &&) _type == T_OBJECT) {
728 if (_depth < _thread->frames_to_pop_failed_realloc()) {
729 // cannot access frame with failed reallocations
730 _result = JVMTI_ERROR_OUT_OF_MEMORY;
731 return false;
732 }
733 if (can_be_deoptimized(jvf)) {
734 compiledVFrame* cf = compiledVFrame::cast(jvf);
735 if (cf->not_global_escape_in_scope() && !_eb.deoptimize_objects(cf)) {
736 // reallocation of scalar replaced objects failed, because heap is exhausted
737 _result = JVMTI_ERROR_OUT_OF_MEMORY;
738 return false;
739 }
740 }
741
742 // With this access the object could escape the thread changing its escape state from ArgEscape,
743 // to GlobalEscape so we must deoptimize callers which could have optimized on the escape state.
744 vframe* vf = jvf;
745 do {
746 // move to next physical frame
747 while(!vf->is_top()) {
748 vf = vf->sender();
749 }
750 vf = vf->sender();
751
752 if (vf != NULL && vf->is_compiled_frame()) {
753 compiledVFrame* cvf = compiledVFrame::cast(vf);
754 // Deoptimize objects if arg escape is being passed down the stack.
755 // Note that deoptimizing the frame is not enough, because objects need to be relocked
756 if (cvf->arg_escape() && !_eb.deoptimize_objects(cvf)) {
757 // reallocation of scalar replaced objects failed, because heap is exhausted
758 _result = JVMTI_ERROR_OUT_OF_MEMORY;
759 return false;
760 }
761 }
762 } while(vf != NULL && !vf->is_entry_frame());
763 }
764 #endif // COMPILER2_OR_JVMCI
765 return true;
766 }
767
768 bool VM_GetOrSetLocal::doit_prologue() {
769 _jvf = get_java_vframe();
770 NULL_CHECK(_jvf, false);
771
772 Method* method_oop = _jvf->method();
773 if (method_oop->is_native()) {
774 if (getting_receiver() && !method_oop->is_static()) {
775 return true;
776 } else {
777 _result = JVMTI_ERROR_OPAQUE_FRAME;
778 return false;
779 }
780 }
781
782 if (!check_slot_type_no_lvt(_jvf)) {
783 return false;
784 }
785 if (method_oop->has_localvariable_table() && !check_slot_type_lvt(_jvf)) {
786 return false;
787 }
788
789 if (!deoptimize_objects(_jvf)) {
790 return false;
791 }
792
793 return true;
794 }
795
796 void VM_GetOrSetLocal::doit() {
797 InterpreterOopMap oop_mask;
798 _jvf->method()->mask_for(_jvf->bci(), &oop_mask);
799 if (oop_mask.is_dead(_index)) {
800 // The local can be invalid and uninitialized in the scope of current bci
801 _result = JVMTI_ERROR_INVALID_SLOT;
802 return;
803 }
804 if (_set) {
805 // Force deoptimization of frame if compiled because it's
806 // possible the compiler emitted some locals as constant values,
807 // meaning they are not mutable.
808 if (can_be_deoptimized(_jvf)) {
809
810 // Schedule deoptimization so that eventually the local
811 // update will be written to an interpreter frame.
812 Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
|