src/share/vm/prims/jvmtiRedefineClasses.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8067713 Sdiff src/share/vm/prims

src/share/vm/prims/jvmtiRedefineClasses.cpp

Print this page




 131       _res = JVMTI_ERROR_INTERNAL;
 132       return;
 133     }
 134   }
 135 
 136   // Mark methods seen on stack and everywhere else so old methods are not
 137   // cleaned up if they're on the stack.
 138   MetadataOnStackMark md_on_stack(true);
 139   HandleMark hm(thread);   // make sure any handles created are deleted
 140                            // before the stack walk again.
 141 
 142   for (int i = 0; i < _class_count; i++) {
 143     redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
 144     ClassLoaderData* cld = _scratch_classes[i]->class_loader_data();
 145     // Free the memory for this class at class unloading time.  Not before
 146     // because CMS might think this is still live.
 147     cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]);
 148     _scratch_classes[i] = NULL;
 149   }
 150 




 151   // Disable any dependent concurrent compilations
 152   SystemDictionary::notice_modification();
 153 
 154   // Set flag indicating that some invariants are no longer true.
 155   // See jvmtiExport.hpp for detailed explanation.
 156   JvmtiExport::set_has_redefined_a_class();
 157 
 158 // check_class() is optionally called for product bits, but is
 159 // always called for non-product bits.
 160 #ifdef PRODUCT
 161   if (RC_TRACE_ENABLED(0x00004000)) {
 162 #endif
 163     RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
 164     CheckClass check_class(thread);
 165     ClassLoaderDataGraph::classes_do(&check_class);
 166 #ifdef PRODUCT
 167   }
 168 #endif
 169 }
 170 
 171 void VM_RedefineClasses::doit_epilogue() {
 172   // Free os::malloc allocated memory.
 173   os::free(_scratch_classes);
 174 
 175   if (RC_TRACE_ENABLED(0x00000004)) {
 176     // Used to have separate timers for "doit" and "all", but the timer
 177     // overhead skewed the measurements.
 178     jlong doit_time = _timer_rsc_phase1.milliseconds() +
 179                       _timer_rsc_phase2.milliseconds();


3423       other_cp = constantPoolHandle(ik->constants());
3424       cp_cache = other_cp->cache();
3425       if (cp_cache != NULL) {
3426         cp_cache->adjust_method_entries(_matching_old_methods,
3427                                         _matching_new_methods,
3428                                         _matching_methods_length,
3429                                         &trace_name_printed);
3430       }
3431     }
3432 
3433     // the previous versions' constant pool caches may need adjustment
3434     for (InstanceKlass* pv_node = ik->previous_versions();
3435          pv_node != NULL;
3436          pv_node = pv_node->previous_versions()) {
3437       cp_cache = pv_node->constants()->cache();
3438       if (cp_cache != NULL) {
3439         cp_cache->adjust_method_entries(_matching_old_methods,
3440                                         _matching_new_methods,
3441                                         _matching_methods_length,
3442                                         &trace_name_printed);
















3443       }
3444     }
3445   }
3446 }
3447 
3448 void VM_RedefineClasses::update_jmethod_ids() {
3449   for (int j = 0; j < _matching_methods_length; ++j) {
3450     Method* old_method = _matching_old_methods[j];
3451     jmethodID jmid = old_method->find_jmethod_id_or_null();
3452     if (jmid != NULL) {
3453       // There is a jmethodID, change it to point to the new method
3454       methodHandle new_method_h(_matching_new_methods[j]);
3455       Method::change_method_associated_with_jmethod_id(jmid, new_method_h());
3456       assert(Method::resolve_jmethod_id(jmid) == _matching_new_methods[j],
3457              "should be replaced");
3458     }
3459   }
3460 }
3461 
3462 int VM_RedefineClasses::check_methods_and_mark_as_obsolete() {




 131       _res = JVMTI_ERROR_INTERNAL;
 132       return;
 133     }
 134   }
 135 
 136   // Mark methods seen on stack and everywhere else so old methods are not
 137   // cleaned up if they're on the stack.
 138   MetadataOnStackMark md_on_stack(true);
 139   HandleMark hm(thread);   // make sure any handles created are deleted
 140                            // before the stack walk again.
 141 
 142   for (int i = 0; i < _class_count; i++) {
 143     redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
 144     ClassLoaderData* cld = _scratch_classes[i]->class_loader_data();
 145     // Free the memory for this class at class unloading time.  Not before
 146     // because CMS might think this is still live.
 147     cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]);
 148     _scratch_classes[i] = NULL;
 149   }
 150 
 151   // Clean out MethodData pointing to old Method*
 152   MethodDataCleaner clean_weak_method_links;
 153   ClassLoaderDataGraph::classes_do(&clean_weak_method_links);
 154 
 155   // Disable any dependent concurrent compilations
 156   SystemDictionary::notice_modification();
 157 
 158   // Set flag indicating that some invariants are no longer true.
 159   // See jvmtiExport.hpp for detailed explanation.
 160   JvmtiExport::set_has_redefined_a_class();
 161 
 162   // check_class() is optionally called for product bits, but is
 163   // always called for non-product bits.
 164 #ifdef PRODUCT
 165   if (RC_TRACE_ENABLED(0x00004000)) {
 166 #endif
 167     RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
 168     CheckClass check_class(thread);
 169     ClassLoaderDataGraph::classes_do(&check_class);
 170 #ifdef PRODUCT
 171   }
 172 #endif
 173 }
 174 
 175 void VM_RedefineClasses::doit_epilogue() {
 176   // Free os::malloc allocated memory.
 177   os::free(_scratch_classes);
 178 
 179   if (RC_TRACE_ENABLED(0x00000004)) {
 180     // Used to have separate timers for "doit" and "all", but the timer
 181     // overhead skewed the measurements.
 182     jlong doit_time = _timer_rsc_phase1.milliseconds() +
 183                       _timer_rsc_phase2.milliseconds();


3427       other_cp = constantPoolHandle(ik->constants());
3428       cp_cache = other_cp->cache();
3429       if (cp_cache != NULL) {
3430         cp_cache->adjust_method_entries(_matching_old_methods,
3431                                         _matching_new_methods,
3432                                         _matching_methods_length,
3433                                         &trace_name_printed);
3434       }
3435     }
3436 
3437     // the previous versions' constant pool caches may need adjustment
3438     for (InstanceKlass* pv_node = ik->previous_versions();
3439          pv_node != NULL;
3440          pv_node = pv_node->previous_versions()) {
3441       cp_cache = pv_node->constants()->cache();
3442       if (cp_cache != NULL) {
3443         cp_cache->adjust_method_entries(_matching_old_methods,
3444                                         _matching_new_methods,
3445                                         _matching_methods_length,
3446                                         &trace_name_printed);
3447       }
3448     }
3449   }
3450 }
3451 
3452 // Clean method data for this class
3453 void VM_RedefineClasses::MethodDataCleaner::do_klass(Klass* k) {
3454   if (k->oop_is_instance()) {
3455     InstanceKlass *ik = InstanceKlass::cast(k);
3456     // Clean MethodData of this class's methods so they don't refer to
3457     // old methods that are no longer running.
3458     Array<Method*>* methods = ik->methods();
3459     int num_methods = methods->length();
3460     for (int index2 = 0; index2 < num_methods; ++index2) {
3461       if (methods->at(index2)->method_data() != NULL) {
3462         methods->at(index2)->method_data()->clean_weak_method_links();
3463       }
3464     }
3465   }
3466 }
3467 
3468 void VM_RedefineClasses::update_jmethod_ids() {
3469   for (int j = 0; j < _matching_methods_length; ++j) {
3470     Method* old_method = _matching_old_methods[j];
3471     jmethodID jmid = old_method->find_jmethod_id_or_null();
3472     if (jmid != NULL) {
3473       // There is a jmethodID, change it to point to the new method
3474       methodHandle new_method_h(_matching_new_methods[j]);
3475       Method::change_method_associated_with_jmethod_id(jmid, new_method_h());
3476       assert(Method::resolve_jmethod_id(jmid) == _matching_new_methods[j],
3477              "should be replaced");
3478     }
3479   }
3480 }
3481 
3482 int VM_RedefineClasses::check_methods_and_mark_as_obsolete() {


src/share/vm/prims/jvmtiRedefineClasses.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File