< prev index next >

src/hotspot/share/prims/jvmtiImpl.cpp

Print this page

 439   , _type(type)
 440   , _value(value)
 441   , _jvf(nullptr)
 442   , _set(set)
 443   , _self(self)
 444   , _result(JVMTI_ERROR_NONE)
 445 {
 446 }
 447 
 448 // Check that the klass is assignable to a type with the given signature.
 449 // Another solution could be to use the function Klass::is_subtype_of(type).
 450 // But the type class can be forced to load/initialize eagerly in such a case.
 451 // This may cause unexpected consequences like CFLH or class-init JVMTI events.
 452 // It is better to avoid such a behavior.
 453 bool VM_BaseGetOrSetLocal::is_assignable(const char* ty_sign, Klass* klass, Thread* thread) {
 454   assert(ty_sign != nullptr, "type signature must not be null");
 455   assert(thread != nullptr, "thread must not be null");
 456   assert(klass != nullptr, "klass must not be null");
 457 
 458   int len = (int) strlen(ty_sign);
 459   if (ty_sign[0] == JVM_SIGNATURE_CLASS &&

 460       ty_sign[len-1] == JVM_SIGNATURE_ENDCLASS) { // Need pure class/interface name
 461     ty_sign++;
 462     len -= 2;
 463   }
 464   TempNewSymbol ty_sym = SymbolTable::new_symbol(ty_sign, len);
 465   if (klass->name() == ty_sym) {
 466     return true;
 467   }
 468   // Compare primary supers
 469   int super_depth = klass->super_depth();
 470   int idx;
 471   for (idx = 0; idx < super_depth; idx++) {
 472     if (klass->primary_super_of_depth(idx)->name() == ty_sym) {
 473       return true;
 474     }
 475   }
 476   // Compare secondary supers
 477   const Array<Klass*>* sec_supers = klass->secondary_supers();
 478   for (idx = 0; idx < sec_supers->length(); idx++) {
 479     if (((Klass*) sec_supers->at(idx))->name() == ty_sym) {

 517     if (_index == (jint) table[i].slot && start_bci <= vf_bci && vf_bci <= end_bci) {
 518       signature_idx = (int) table[i].descriptor_cp_index;
 519       break;
 520     }
 521   }
 522   if (signature_idx == -1) {
 523     _result = JVMTI_ERROR_INVALID_SLOT;
 524     return false;       // Incorrect slot index
 525   }
 526   Symbol*   sign_sym  = method->constants()->symbol_at(signature_idx);
 527   BasicType slot_type = Signature::basic_type(sign_sym);
 528 
 529   switch (slot_type) {
 530   case T_BYTE:
 531   case T_SHORT:
 532   case T_CHAR:
 533   case T_BOOLEAN:
 534     slot_type = T_INT;
 535     break;
 536   case T_ARRAY:

 537     slot_type = T_OBJECT;
 538     break;
 539   default:
 540     break;
 541   };
 542   if (_type != slot_type) {
 543     _result = JVMTI_ERROR_TYPE_MISMATCH;
 544     return false;
 545   }
 546 
 547   jobject jobj = _value.l;
 548   if (_set && slot_type == T_OBJECT && jobj != nullptr) { // null reference is allowed
 549     // Check that the jobject class matches the return type signature.
 550     oop obj = JNIHandles::resolve_external_guard(jobj);
 551     NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
 552     Klass* ob_k = obj->klass();
 553     NULL_CHECK(ob_k, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
 554 
 555     const char* signature = (const char *) sign_sym->as_utf8();
 556     if (!is_assignable(signature, ob_k, VMThread::vm_thread())) {

 664       if (Continuation::is_frame_in_continuation(_jvf->thread(), fr)) {
 665         _result = JVMTI_ERROR_OPAQUE_FRAME; // can't deoptimize for top continuation frame
 666         return;
 667       }
 668 
 669       // Schedule deoptimization so that eventually the local
 670       // update will be written to an interpreter frame.
 671       Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
 672 
 673       // Now store a new value for the local which will be applied
 674       // once deoptimization occurs. Note however that while this
 675       // write is deferred until deoptimization actually happens
 676       // can vframe created after this point will have its locals
 677       // reflecting this update so as far as anyone can see the
 678       // write has already taken place.
 679 
 680       // If we are updating an oop then get the oop from the handle
 681       // since the handle will be long gone by the time the deopt
 682       // happens. The oop stored in the deferred local will be
 683       // gc'd on its own.
 684       if (_type == T_OBJECT) {
 685         _value.l = cast_from_oop<jobject>(JNIHandles::resolve_external_guard(_value.l));
 686       }
 687       // Re-read the vframe so we can see that it is deoptimized
 688       // [ Only need because of assert in update_local() ]
 689       _jvf = get_java_vframe();
 690       ((compiledVFrame*)_jvf)->update_local(_type, _index, _value);
 691       return;
 692     }
 693     StackValueCollection *locals = _jvf->locals();
 694     Thread* current_thread = VMThread::vm_thread();
 695     HandleMark hm(current_thread);
 696 
 697     switch (_type) {
 698       case T_INT:    locals->set_int_at   (_index, _value.i); break;
 699       case T_LONG:   locals->set_long_at  (_index, _value.j); break;
 700       case T_FLOAT:  locals->set_float_at (_index, _value.f); break;
 701       case T_DOUBLE: locals->set_double_at(_index, _value.d); break;
 702       case T_OBJECT: {

 703         Handle ob_h(current_thread, JNIHandles::resolve_external_guard(_value.l));
 704         locals->set_obj_at (_index, ob_h);
 705         break;
 706       }
 707       default: ShouldNotReachHere();
 708     }
 709     _jvf->set_locals(locals);
 710   } else {
 711     if (_jvf->method()->is_native() && _jvf->is_compiled_frame()) {
 712       assert(getting_receiver(), "Can only get here when getting receiver");
 713       oop receiver = _jvf->fr().get_native_receiver();
 714       _value.l = JNIHandles::make_local(_calling_thread, receiver);
 715     } else {
 716       StackValueCollection *locals = _jvf->locals();
 717 
 718       switch (_type) {
 719         case T_INT:    _value.i = locals->int_at   (_index);   break;
 720         case T_LONG:   _value.j = locals->long_at  (_index);   break;
 721         case T_FLOAT:  _value.f = locals->float_at (_index);   break;
 722         case T_DOUBLE: _value.d = locals->double_at(_index);   break;
 723         case T_OBJECT: {

 724           // Wrap the oop to be returned in a local JNI handle since
 725           // oops_do() no longer applies after doit() is finished.
 726           oop obj = locals->obj_at(_index)();
 727           _value.l = JNIHandles::make_local(_calling_thread, obj);
 728           break;
 729         }
 730         default: ShouldNotReachHere();
 731       }
 732     }
 733   }
 734 }
 735 
 736 bool VM_BaseGetOrSetLocal::allow_nested_vm_operations() const {
 737   return true; // May need to deoptimize
 738 }
 739 
 740 
 741 ///////////////////////////////////////////////////////////////
 742 //
 743 // class VM_GetOrSetLocal

 439   , _type(type)
 440   , _value(value)
 441   , _jvf(nullptr)
 442   , _set(set)
 443   , _self(self)
 444   , _result(JVMTI_ERROR_NONE)
 445 {
 446 }
 447 
 448 // Check that the klass is assignable to a type with the given signature.
 449 // Another solution could be to use the function Klass::is_subtype_of(type).
 450 // But the type class can be forced to load/initialize eagerly in such a case.
 451 // This may cause unexpected consequences like CFLH or class-init JVMTI events.
 452 // It is better to avoid such a behavior.
 453 bool VM_BaseGetOrSetLocal::is_assignable(const char* ty_sign, Klass* klass, Thread* thread) {
 454   assert(ty_sign != nullptr, "type signature must not be null");
 455   assert(thread != nullptr, "thread must not be null");
 456   assert(klass != nullptr, "klass must not be null");
 457 
 458   int len = (int) strlen(ty_sign);
 459   if ((ty_sign[0] == JVM_SIGNATURE_CLASS ||
 460        ty_sign[0] == JVM_SIGNATURE_PRIMITIVE_OBJECT) &&
 461       ty_sign[len-1] == JVM_SIGNATURE_ENDCLASS) { // Need pure class/interface name
 462     ty_sign++;
 463     len -= 2;
 464   }
 465   TempNewSymbol ty_sym = SymbolTable::new_symbol(ty_sign, len);
 466   if (klass->name() == ty_sym) {
 467     return true;
 468   }
 469   // Compare primary supers
 470   int super_depth = klass->super_depth();
 471   int idx;
 472   for (idx = 0; idx < super_depth; idx++) {
 473     if (klass->primary_super_of_depth(idx)->name() == ty_sym) {
 474       return true;
 475     }
 476   }
 477   // Compare secondary supers
 478   const Array<Klass*>* sec_supers = klass->secondary_supers();
 479   for (idx = 0; idx < sec_supers->length(); idx++) {
 480     if (((Klass*) sec_supers->at(idx))->name() == ty_sym) {

 518     if (_index == (jint) table[i].slot && start_bci <= vf_bci && vf_bci <= end_bci) {
 519       signature_idx = (int) table[i].descriptor_cp_index;
 520       break;
 521     }
 522   }
 523   if (signature_idx == -1) {
 524     _result = JVMTI_ERROR_INVALID_SLOT;
 525     return false;       // Incorrect slot index
 526   }
 527   Symbol*   sign_sym  = method->constants()->symbol_at(signature_idx);
 528   BasicType slot_type = Signature::basic_type(sign_sym);
 529 
 530   switch (slot_type) {
 531   case T_BYTE:
 532   case T_SHORT:
 533   case T_CHAR:
 534   case T_BOOLEAN:
 535     slot_type = T_INT;
 536     break;
 537   case T_ARRAY:
 538   case T_PRIMITIVE_OBJECT:
 539     slot_type = T_OBJECT;
 540     break;
 541   default:
 542     break;
 543   };
 544   if (_type != slot_type) {
 545     _result = JVMTI_ERROR_TYPE_MISMATCH;
 546     return false;
 547   }
 548 
 549   jobject jobj = _value.l;
 550   if (_set && slot_type == T_OBJECT && jobj != nullptr) { // null reference is allowed
 551     // Check that the jobject class matches the return type signature.
 552     oop obj = JNIHandles::resolve_external_guard(jobj);
 553     NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
 554     Klass* ob_k = obj->klass();
 555     NULL_CHECK(ob_k, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
 556 
 557     const char* signature = (const char *) sign_sym->as_utf8();
 558     if (!is_assignable(signature, ob_k, VMThread::vm_thread())) {

 666       if (Continuation::is_frame_in_continuation(_jvf->thread(), fr)) {
 667         _result = JVMTI_ERROR_OPAQUE_FRAME; // can't deoptimize for top continuation frame
 668         return;
 669       }
 670 
 671       // Schedule deoptimization so that eventually the local
 672       // update will be written to an interpreter frame.
 673       Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
 674 
 675       // Now store a new value for the local which will be applied
 676       // once deoptimization occurs. Note however that while this
 677       // write is deferred until deoptimization actually happens
 678       // can vframe created after this point will have its locals
 679       // reflecting this update so as far as anyone can see the
 680       // write has already taken place.
 681 
 682       // If we are updating an oop then get the oop from the handle
 683       // since the handle will be long gone by the time the deopt
 684       // happens. The oop stored in the deferred local will be
 685       // gc'd on its own.
 686       if (_type == T_OBJECT || _type == T_PRIMITIVE_OBJECT) {
 687         _value.l = cast_from_oop<jobject>(JNIHandles::resolve_external_guard(_value.l));
 688       }
 689       // Re-read the vframe so we can see that it is deoptimized
 690       // [ Only need because of assert in update_local() ]
 691       _jvf = get_java_vframe();
 692       ((compiledVFrame*)_jvf)->update_local(_type, _index, _value);
 693       return;
 694     }
 695     StackValueCollection *locals = _jvf->locals();
 696     Thread* current_thread = VMThread::vm_thread();
 697     HandleMark hm(current_thread);
 698 
 699     switch (_type) {
 700       case T_INT:    locals->set_int_at   (_index, _value.i); break;
 701       case T_LONG:   locals->set_long_at  (_index, _value.j); break;
 702       case T_FLOAT:  locals->set_float_at (_index, _value.f); break;
 703       case T_DOUBLE: locals->set_double_at(_index, _value.d); break;
 704       case T_OBJECT:
 705       case T_PRIMITIVE_OBJECT: {
 706         Handle ob_h(current_thread, JNIHandles::resolve_external_guard(_value.l));
 707         locals->set_obj_at (_index, ob_h);
 708         break;
 709       }
 710       default: ShouldNotReachHere();
 711     }
 712     _jvf->set_locals(locals);
 713   } else {
 714     if (_jvf->method()->is_native() && _jvf->is_compiled_frame()) {
 715       assert(getting_receiver(), "Can only get here when getting receiver");
 716       oop receiver = _jvf->fr().get_native_receiver();
 717       _value.l = JNIHandles::make_local(_calling_thread, receiver);
 718     } else {
 719       StackValueCollection *locals = _jvf->locals();
 720 
 721       switch (_type) {
 722         case T_INT:    _value.i = locals->int_at   (_index);   break;
 723         case T_LONG:   _value.j = locals->long_at  (_index);   break;
 724         case T_FLOAT:  _value.f = locals->float_at (_index);   break;
 725         case T_DOUBLE: _value.d = locals->double_at(_index);   break;
 726         case T_OBJECT:
 727         case T_PRIMITIVE_OBJECT: {
 728           // Wrap the oop to be returned in a local JNI handle since
 729           // oops_do() no longer applies after doit() is finished.
 730           oop obj = locals->obj_at(_index)();
 731           _value.l = JNIHandles::make_local(_calling_thread, obj);
 732           break;
 733         }
 734         default: ShouldNotReachHere();
 735       }
 736     }
 737   }
 738 }
 739 
 740 bool VM_BaseGetOrSetLocal::allow_nested_vm_operations() const {
 741   return true; // May need to deoptimize
 742 }
 743 
 744 
 745 ///////////////////////////////////////////////////////////////
 746 //
 747 // class VM_GetOrSetLocal
< prev index next >