< prev index next >

src/hotspot/share/prims/jvmtiImpl.cpp

Print this page

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

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

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

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

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

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

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

 438   , _index(index)
 439   , _type(type)
 440   , _value(value)
 441   , _jvf(NULL)
 442   , _set(set)
 443   , _result(JVMTI_ERROR_NONE)
 444 {
 445 }
 446 
 447 // Check that the klass is assignable to a type with the given signature.
 448 // Another solution could be to use the function Klass::is_subtype_of(type).
 449 // But the type class can be forced to load/initialize eagerly in such a case.
 450 // This may cause unexpected consequences like CFLH or class-init JVMTI events.
 451 // It is better to avoid such a behavior.
 452 bool VM_BaseGetOrSetLocal::is_assignable(const char* ty_sign, Klass* klass, Thread* thread) {
 453   assert(ty_sign != NULL, "type signature must not be NULL");
 454   assert(thread != NULL, "thread must not be NULL");
 455   assert(klass != NULL, "klass must not be NULL");
 456 
 457   int len = (int) strlen(ty_sign);
 458   if ((ty_sign[0] == JVM_SIGNATURE_CLASS ||
 459        ty_sign[0] == JVM_SIGNATURE_PRIMITIVE_OBJECT) &&
 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   case T_PRIMITIVE_OBJECT:
 538     slot_type = T_OBJECT;
 539     break;
 540   default:
 541     break;
 542   };
 543   if (_type != slot_type) {
 544     _result = JVMTI_ERROR_TYPE_MISMATCH;
 545     return false;
 546   }
 547 
 548   jobject jobj = _value.l;
 549   if (_set && slot_type == T_OBJECT && jobj != NULL) { // NULL reference is allowed
 550     // Check that the jobject class matches the return type signature.
 551     oop obj = JNIHandles::resolve_external_guard(jobj);
 552     NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
 553     Klass* ob_k = obj->klass();
 554     NULL_CHECK(ob_k, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
 555 
 556     const char* signature = (const char *) sign_sym->as_utf8();
 557     if (!is_assignable(signature, ob_k, VMThread::vm_thread())) {

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