493 javaVFrame *jvf = (javaVFrame*)vf;
494
495 if (!vf->is_java_frame()) {
496 _result = JVMTI_ERROR_OPAQUE_FRAME;
497 return NULL;
498 }
499 return jvf;
500 }
501
502 // Check that the klass is assignable to a type with the given signature.
503 // Another solution could be to use the function Klass::is_subtype_of(type).
504 // But the type class can be forced to load/initialize eagerly in such a case.
505 // This may cause unexpected consequences like CFLH or class-init JVMTI events.
506 // It is better to avoid such a behavior.
507 bool VM_GetOrSetLocal::is_assignable(const char* ty_sign, Klass* klass, Thread* thread) {
508 assert(ty_sign != NULL, "type signature must not be NULL");
509 assert(thread != NULL, "thread must not be NULL");
510 assert(klass != NULL, "klass must not be NULL");
511
512 int len = (int) strlen(ty_sign);
513 if (ty_sign[0] == JVM_SIGNATURE_CLASS &&
514 ty_sign[len-1] == JVM_SIGNATURE_ENDCLASS) { // Need pure class/interface name
515 ty_sign++;
516 len -= 2;
517 }
518 TempNewSymbol ty_sym = SymbolTable::new_symbol(ty_sign, len);
519 if (klass->name() == ty_sym) {
520 return true;
521 }
522 // Compare primary supers
523 int super_depth = klass->super_depth();
524 int idx;
525 for (idx = 0; idx < super_depth; idx++) {
526 if (klass->primary_super_of_depth(idx)->name() == ty_sym) {
527 return true;
528 }
529 }
530 // Compare secondary supers
531 const Array<Klass*>* sec_supers = klass->secondary_supers();
532 for (idx = 0; idx < sec_supers->length(); idx++) {
533 if (((Klass*) sec_supers->at(idx))->name() == ty_sym) {
561 if (_index == (jint) table[i].slot && start_bci <= vf_bci && vf_bci <= end_bci) {
562 signature_idx = (int) table[i].descriptor_cp_index;
563 break;
564 }
565 }
566 if (signature_idx == -1) {
567 _result = JVMTI_ERROR_INVALID_SLOT;
568 return false; // Incorrect slot index
569 }
570 Symbol* sign_sym = method->constants()->symbol_at(signature_idx);
571 BasicType slot_type = Signature::basic_type(sign_sym);
572
573 switch (slot_type) {
574 case T_BYTE:
575 case T_SHORT:
576 case T_CHAR:
577 case T_BOOLEAN:
578 slot_type = T_INT;
579 break;
580 case T_ARRAY:
581 slot_type = T_OBJECT;
582 break;
583 default:
584 break;
585 };
586 if (_type != slot_type) {
587 _result = JVMTI_ERROR_TYPE_MISMATCH;
588 return false;
589 }
590
591 jobject jobj = _value.l;
592 if (_set && slot_type == T_OBJECT && jobj != NULL) { // NULL reference is allowed
593 // Check that the jobject class matches the return type signature.
594 oop obj = JNIHandles::resolve_external_guard(jobj);
595 NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
596 Klass* ob_k = obj->klass();
597 NULL_CHECK(ob_k, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
598
599 const char* signature = (const char *) sign_sym->as_utf8();
600 if (!is_assignable(signature, ob_k, VMThread::vm_thread())) {
686 // Force deoptimization of frame if compiled because it's
687 // possible the compiler emitted some locals as constant values,
688 // meaning they are not mutable.
689 if (can_be_deoptimized(_jvf)) {
690
691 // Schedule deoptimization so that eventually the local
692 // update will be written to an interpreter frame.
693 Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
694
695 // Now store a new value for the local which will be applied
696 // once deoptimization occurs. Note however that while this
697 // write is deferred until deoptimization actually happens
698 // can vframe created after this point will have its locals
699 // reflecting this update so as far as anyone can see the
700 // write has already taken place.
701
702 // If we are updating an oop then get the oop from the handle
703 // since the handle will be long gone by the time the deopt
704 // happens. The oop stored in the deferred local will be
705 // gc'd on its own.
706 if (_type == T_OBJECT) {
707 _value.l = cast_from_oop<jobject>(JNIHandles::resolve_external_guard(_value.l));
708 }
709 // Re-read the vframe so we can see that it is deoptimized
710 // [ Only need because of assert in update_local() ]
711 _jvf = get_java_vframe();
712 ((compiledVFrame*)_jvf)->update_local(_type, _index, _value);
713 return;
714 }
715 StackValueCollection *locals = _jvf->locals();
716 Thread* current_thread = VMThread::vm_thread();
717 HandleMark hm(current_thread);
718
719 switch (_type) {
720 case T_INT: locals->set_int_at (_index, _value.i); break;
721 case T_LONG: locals->set_long_at (_index, _value.j); break;
722 case T_FLOAT: locals->set_float_at (_index, _value.f); break;
723 case T_DOUBLE: locals->set_double_at(_index, _value.d); break;
724 case T_OBJECT: {
725 Handle ob_h(current_thread, JNIHandles::resolve_external_guard(_value.l));
726 locals->set_obj_at (_index, ob_h);
727 break;
728 }
729 default: ShouldNotReachHere();
730 }
731 _jvf->set_locals(locals);
732 } else {
733 if (_jvf->method()->is_native() && _jvf->is_compiled_frame()) {
734 assert(getting_receiver(), "Can only get here when getting receiver");
735 oop receiver = _jvf->fr().get_native_receiver();
736 _value.l = JNIHandles::make_local(_calling_thread, receiver);
737 } else {
738 StackValueCollection *locals = _jvf->locals();
739
740 switch (_type) {
741 case T_INT: _value.i = locals->int_at (_index); break;
742 case T_LONG: _value.j = locals->long_at (_index); break;
743 case T_FLOAT: _value.f = locals->float_at (_index); break;
744 case T_DOUBLE: _value.d = locals->double_at(_index); break;
745 case T_OBJECT: {
746 // Wrap the oop to be returned in a local JNI handle since
747 // oops_do() no longer applies after doit() is finished.
748 oop obj = locals->obj_at(_index)();
749 _value.l = JNIHandles::make_local(_calling_thread, obj);
750 break;
751 }
752 default: ShouldNotReachHere();
753 }
754 }
755 }
756 }
757
758
759 bool VM_GetOrSetLocal::allow_nested_vm_operations() const {
760 return true; // May need to deoptimize
761 }
762
763
764 VM_GetReceiver::VM_GetReceiver(
765 JavaThread* thread, JavaThread* caller_thread, jint depth)
|
493 javaVFrame *jvf = (javaVFrame*)vf;
494
495 if (!vf->is_java_frame()) {
496 _result = JVMTI_ERROR_OPAQUE_FRAME;
497 return NULL;
498 }
499 return jvf;
500 }
501
502 // Check that the klass is assignable to a type with the given signature.
503 // Another solution could be to use the function Klass::is_subtype_of(type).
504 // But the type class can be forced to load/initialize eagerly in such a case.
505 // This may cause unexpected consequences like CFLH or class-init JVMTI events.
506 // It is better to avoid such a behavior.
507 bool VM_GetOrSetLocal::is_assignable(const char* ty_sign, Klass* klass, Thread* thread) {
508 assert(ty_sign != NULL, "type signature must not be NULL");
509 assert(thread != NULL, "thread must not be NULL");
510 assert(klass != NULL, "klass must not be NULL");
511
512 int len = (int) strlen(ty_sign);
513 if ((ty_sign[0] == JVM_SIGNATURE_CLASS ||
514 ty_sign[0] == JVM_SIGNATURE_PRIMITIVE_OBJECT) &&
515 ty_sign[len-1] == JVM_SIGNATURE_ENDCLASS) { // Need pure class/interface name
516 ty_sign++;
517 len -= 2;
518 }
519 TempNewSymbol ty_sym = SymbolTable::new_symbol(ty_sign, len);
520 if (klass->name() == ty_sym) {
521 return true;
522 }
523 // Compare primary supers
524 int super_depth = klass->super_depth();
525 int idx;
526 for (idx = 0; idx < super_depth; idx++) {
527 if (klass->primary_super_of_depth(idx)->name() == ty_sym) {
528 return true;
529 }
530 }
531 // Compare secondary supers
532 const Array<Klass*>* sec_supers = klass->secondary_supers();
533 for (idx = 0; idx < sec_supers->length(); idx++) {
534 if (((Klass*) sec_supers->at(idx))->name() == ty_sym) {
562 if (_index == (jint) table[i].slot && start_bci <= vf_bci && vf_bci <= end_bci) {
563 signature_idx = (int) table[i].descriptor_cp_index;
564 break;
565 }
566 }
567 if (signature_idx == -1) {
568 _result = JVMTI_ERROR_INVALID_SLOT;
569 return false; // Incorrect slot index
570 }
571 Symbol* sign_sym = method->constants()->symbol_at(signature_idx);
572 BasicType slot_type = Signature::basic_type(sign_sym);
573
574 switch (slot_type) {
575 case T_BYTE:
576 case T_SHORT:
577 case T_CHAR:
578 case T_BOOLEAN:
579 slot_type = T_INT;
580 break;
581 case T_ARRAY:
582 case T_PRIMITIVE_OBJECT:
583 slot_type = T_OBJECT;
584 break;
585 default:
586 break;
587 };
588 if (_type != slot_type) {
589 _result = JVMTI_ERROR_TYPE_MISMATCH;
590 return false;
591 }
592
593 jobject jobj = _value.l;
594 if (_set && slot_type == T_OBJECT && jobj != NULL) { // NULL reference is allowed
595 // Check that the jobject class matches the return type signature.
596 oop obj = JNIHandles::resolve_external_guard(jobj);
597 NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
598 Klass* ob_k = obj->klass();
599 NULL_CHECK(ob_k, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
600
601 const char* signature = (const char *) sign_sym->as_utf8();
602 if (!is_assignable(signature, ob_k, VMThread::vm_thread())) {
688 // Force deoptimization of frame if compiled because it's
689 // possible the compiler emitted some locals as constant values,
690 // meaning they are not mutable.
691 if (can_be_deoptimized(_jvf)) {
692
693 // Schedule deoptimization so that eventually the local
694 // update will be written to an interpreter frame.
695 Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
696
697 // Now store a new value for the local which will be applied
698 // once deoptimization occurs. Note however that while this
699 // write is deferred until deoptimization actually happens
700 // can vframe created after this point will have its locals
701 // reflecting this update so as far as anyone can see the
702 // write has already taken place.
703
704 // If we are updating an oop then get the oop from the handle
705 // since the handle will be long gone by the time the deopt
706 // happens. The oop stored in the deferred local will be
707 // gc'd on its own.
708 if (_type == T_OBJECT || _type == T_PRIMITIVE_OBJECT) {
709 _value.l = cast_from_oop<jobject>(JNIHandles::resolve_external_guard(_value.l));
710 }
711 // Re-read the vframe so we can see that it is deoptimized
712 // [ Only need because of assert in update_local() ]
713 _jvf = get_java_vframe();
714 ((compiledVFrame*)_jvf)->update_local(_type, _index, _value);
715 return;
716 }
717 StackValueCollection *locals = _jvf->locals();
718 Thread* current_thread = VMThread::vm_thread();
719 HandleMark hm(current_thread);
720
721 switch (_type) {
722 case T_INT: locals->set_int_at (_index, _value.i); break;
723 case T_LONG: locals->set_long_at (_index, _value.j); break;
724 case T_FLOAT: locals->set_float_at (_index, _value.f); break;
725 case T_DOUBLE: locals->set_double_at(_index, _value.d); break;
726 case T_OBJECT:
727 case T_PRIMITIVE_OBJECT: {
728 Handle ob_h(current_thread, JNIHandles::resolve_external_guard(_value.l));
729 locals->set_obj_at (_index, ob_h);
730 break;
731 }
732 default: ShouldNotReachHere();
733 }
734 _jvf->set_locals(locals);
735 } else {
736 if (_jvf->method()->is_native() && _jvf->is_compiled_frame()) {
737 assert(getting_receiver(), "Can only get here when getting receiver");
738 oop receiver = _jvf->fr().get_native_receiver();
739 _value.l = JNIHandles::make_local(_calling_thread, receiver);
740 } else {
741 StackValueCollection *locals = _jvf->locals();
742
743 switch (_type) {
744 case T_INT: _value.i = locals->int_at (_index); break;
745 case T_LONG: _value.j = locals->long_at (_index); break;
746 case T_FLOAT: _value.f = locals->float_at (_index); break;
747 case T_DOUBLE: _value.d = locals->double_at(_index); break;
748 case T_OBJECT:
749 case T_PRIMITIVE_OBJECT: {
750 // Wrap the oop to be returned in a local JNI handle since
751 // oops_do() no longer applies after doit() is finished.
752 oop obj = locals->obj_at(_index)();
753 _value.l = JNIHandles::make_local(_calling_thread, obj);
754 break;
755 }
756 default: ShouldNotReachHere();
757 }
758 }
759 }
760 }
761
762
763 bool VM_GetOrSetLocal::allow_nested_vm_operations() const {
764 return true; // May need to deoptimize
765 }
766
767
768 VM_GetReceiver::VM_GetReceiver(
769 JavaThread* thread, JavaThread* caller_thread, jint depth)
|