424 debug_only(int n = this_jvmti->length(););
425 assert(cache[n] == NULL, "cache must be NULL terminated");
426
427 set_breakpoint_list(cache);
428 }
429
430 ///////////////////////////////////////////////////////////////
431 //
432 // class VM_GetOrSetLocal
433 //
434
435 // Constructor for non-object getter
436 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type)
437 : _thread(thread)
438 , _calling_thread(NULL)
439 , _depth(depth)
440 , _index(index)
441 , _type(type)
442 , _jvf(NULL)
443 , _set(false)
444 , _result(JVMTI_ERROR_NONE)
445 {
446 }
447
448 // Constructor for object or non-object setter
449 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value)
450 : _thread(thread)
451 , _calling_thread(NULL)
452 , _depth(depth)
453 , _index(index)
454 , _type(type)
455 , _value(value)
456 , _jvf(NULL)
457 , _set(true)
458 , _result(JVMTI_ERROR_NONE)
459 {
460 }
461
462 // Constructor for object getter
463 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth, int index)
464 : _thread(thread)
465 , _calling_thread(calling_thread)
466 , _depth(depth)
467 , _index(index)
468 , _type(T_OBJECT)
469 , _jvf(NULL)
470 , _set(false)
471 , _result(JVMTI_ERROR_NONE)
472 {
473 }
474
475 vframe *VM_GetOrSetLocal::get_vframe() {
476 if (!_thread->has_last_Java_frame()) {
477 return NULL;
478 }
479 RegisterMap reg_map(_thread);
480 vframe *vf = _thread->last_java_vframe(®_map);
481 int d = 0;
482 while ((vf != NULL) && (d < _depth)) {
483 vf = vf->java_sender();
484 d++;
485 }
486 return vf;
487 }
488
489 javaVFrame *VM_GetOrSetLocal::get_java_vframe() {
490 vframe* vf = get_vframe();
626 return false;
627 }
628 if (extra_slot) {
629 BasicType extra_slot_type = locals->at(_index + 1)->type();
630 if (extra_slot_type != T_INT) {
631 _result = JVMTI_ERROR_INVALID_SLOT;
632 return false;
633 }
634 }
635 if (_type != slot_type && (_type == T_OBJECT || slot_type != T_INT)) {
636 _result = JVMTI_ERROR_TYPE_MISMATCH;
637 return false;
638 }
639 return true;
640 }
641
642 static bool can_be_deoptimized(vframe* vf) {
643 return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized());
644 }
645
646 bool VM_GetOrSetLocal::doit_prologue() {
647 _jvf = get_java_vframe();
648 NULL_CHECK(_jvf, false);
649
650 Method* method_oop = _jvf->method();
651 if (getting_receiver()) {
652 if (method_oop->is_static()) {
653 _result = JVMTI_ERROR_INVALID_SLOT;
654 return false;
655 }
656 return true;
657 }
658
659 if (method_oop->is_native()) {
660 _result = JVMTI_ERROR_OPAQUE_FRAME;
661 return false;
662 }
663
664 if (!check_slot_type_no_lvt(_jvf)) {
665 return false;
666 }
667 if (method_oop->has_localvariable_table()) {
668 return check_slot_type_lvt(_jvf);
669 }
670 return true;
671 }
672
673 void VM_GetOrSetLocal::doit() {
674 InterpreterOopMap oop_mask;
675 _jvf->method()->mask_for(_jvf->bci(), &oop_mask);
676 if (oop_mask.is_dead(_index)) {
677 // The local can be invalid and uninitialized in the scope of current bci
678 _result = JVMTI_ERROR_INVALID_SLOT;
679 return;
680 }
681 if (_set) {
682 // Force deoptimization of frame if compiled because it's
683 // possible the compiler emitted some locals as constant values,
684 // meaning they are not mutable.
685 if (can_be_deoptimized(_jvf)) {
686
687 // Schedule deoptimization so that eventually the local
688 // update will be written to an interpreter frame.
689 Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
|
424 debug_only(int n = this_jvmti->length(););
425 assert(cache[n] == NULL, "cache must be NULL terminated");
426
427 set_breakpoint_list(cache);
428 }
429
430 ///////////////////////////////////////////////////////////////
431 //
432 // class VM_GetOrSetLocal
433 //
434
435 // Constructor for non-object getter
436 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type)
437 : _thread(thread)
438 , _calling_thread(NULL)
439 , _depth(depth)
440 , _index(index)
441 , _type(type)
442 , _jvf(NULL)
443 , _set(false)
444 , _eb(NULL, NULL, false) // no references escape
445 , _result(JVMTI_ERROR_NONE)
446 {
447 }
448
449 // Constructor for object or non-object setter
450 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value)
451 : _thread(thread)
452 , _calling_thread(NULL)
453 , _depth(depth)
454 , _index(index)
455 , _type(type)
456 , _value(value)
457 , _jvf(NULL)
458 , _set(true)
459 , _eb(JavaThread::current(), thread, type == T_OBJECT)
460 , _result(JVMTI_ERROR_NONE)
461 {
462 }
463
464 // Constructor for object getter
465 VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth, int index)
466 : _thread(thread)
467 , _calling_thread(calling_thread)
468 , _depth(depth)
469 , _index(index)
470 , _type(T_OBJECT)
471 , _jvf(NULL)
472 , _set(false)
473 , _eb(calling_thread, thread, true)
474 , _result(JVMTI_ERROR_NONE)
475 {
476 }
477
478 vframe *VM_GetOrSetLocal::get_vframe() {
479 if (!_thread->has_last_Java_frame()) {
480 return NULL;
481 }
482 RegisterMap reg_map(_thread);
483 vframe *vf = _thread->last_java_vframe(®_map);
484 int d = 0;
485 while ((vf != NULL) && (d < _depth)) {
486 vf = vf->java_sender();
487 d++;
488 }
489 return vf;
490 }
491
492 javaVFrame *VM_GetOrSetLocal::get_java_vframe() {
493 vframe* vf = get_vframe();
629 return false;
630 }
631 if (extra_slot) {
632 BasicType extra_slot_type = locals->at(_index + 1)->type();
633 if (extra_slot_type != T_INT) {
634 _result = JVMTI_ERROR_INVALID_SLOT;
635 return false;
636 }
637 }
638 if (_type != slot_type && (_type == T_OBJECT || slot_type != T_INT)) {
639 _result = JVMTI_ERROR_TYPE_MISMATCH;
640 return false;
641 }
642 return true;
643 }
644
645 static bool can_be_deoptimized(vframe* vf) {
646 return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized());
647 }
648
649 // Revert optimizations based on escape analysis if this is an access to a local object
650 bool VM_GetOrSetLocal::deoptimize_objects(javaVFrame* jvf) {
651 #if COMPILER2_OR_JVMCI
652 if (NOT_JVMCI(DoEscapeAnalysis &&) _type == T_OBJECT) {
653 if (_depth < _thread->frames_to_pop_failed_realloc()) {
654 // cannot access frame with failed reallocations
655 _result = JVMTI_ERROR_OUT_OF_MEMORY;
656 return false;
657 }
658 if (can_be_deoptimized(jvf)) {
659 compiledVFrame* cf = compiledVFrame::cast(jvf);
660 if (cf->not_global_escape_in_scope() && !_eb.deoptimize_objects(cf->fr().id())) {
661 // reallocation of scalar replaced objects failed, because heap is exhausted
662 _result = JVMTI_ERROR_OUT_OF_MEMORY;
663 return false;
664 }
665 }
666
667 // With this access the object could escape the thread changing its escape state from ArgEscape,
668 // to GlobalEscape so we must deoptimize callers which could have optimized on the escape state.
669 vframe* vf = jvf;
670 do {
671 // move to next physical frame
672 while(!vf->is_top()) {
673 vf = vf->sender();
674 }
675 vf = vf->sender();
676
677 if (vf != NULL && vf->is_compiled_frame()) {
678 compiledVFrame* cvf = compiledVFrame::cast(vf);
679 // Deoptimize objects if arg escape is being passed down the stack.
680 // Note that deoptimizing the frame is not enough, because objects need to be relocked
681 if (cvf->arg_escape() && !_eb.deoptimize_objects(cvf->fr().id())) {
682 // reallocation of scalar replaced objects failed, because heap is exhausted
683 _result = JVMTI_ERROR_OUT_OF_MEMORY;
684 return false;
685 }
686 }
687 } while(vf != NULL && !vf->is_entry_frame());
688 }
689 #endif // COMPILER2_OR_JVMCI
690 return true;
691 }
692
693 bool VM_GetOrSetLocal::doit_prologue() {
694 _jvf = get_java_vframe();
695 NULL_CHECK(_jvf, false);
696
697 Method* method_oop = _jvf->method();
698 if (getting_receiver()) {
699 if (method_oop->is_static()) {
700 _result = JVMTI_ERROR_INVALID_SLOT;
701 return false;
702 }
703 return true;
704 }
705
706 if (method_oop->is_native()) {
707 _result = JVMTI_ERROR_OPAQUE_FRAME;
708 return false;
709 }
710
711 if (!check_slot_type_no_lvt(_jvf)) {
712 return false;
713 }
714 if (method_oop->has_localvariable_table() && !check_slot_type_lvt(_jvf)) {
715 return false;
716 }
717
718 if (!deoptimize_objects(_jvf)) {
719 return false;
720 }
721
722 return true;
723 }
724
725 void VM_GetOrSetLocal::doit() {
726 InterpreterOopMap oop_mask;
727 _jvf->method()->mask_for(_jvf->bci(), &oop_mask);
728 if (oop_mask.is_dead(_index)) {
729 // The local can be invalid and uninitialized in the scope of current bci
730 _result = JVMTI_ERROR_INVALID_SLOT;
731 return;
732 }
733 if (_set) {
734 // Force deoptimization of frame if compiled because it's
735 // possible the compiler emitted some locals as constant values,
736 // meaning they are not mutable.
737 if (can_be_deoptimized(_jvf)) {
738
739 // Schedule deoptimization so that eventually the local
740 // update will be written to an interpreter frame.
741 Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
|