hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp
changeset 26558 b7df27df6384
parent 24459 ebd373039673
child 27401 a4697c9502cb
equal deleted inserted replaced
26557:e399effe36f9 26558:b7df27df6384
   133     }
   133     }
   134   }
   134   }
   135 
   135 
   136   // Mark methods seen on stack and everywhere else so old methods are not
   136   // Mark methods seen on stack and everywhere else so old methods are not
   137   // cleaned up if they're on the stack.
   137   // cleaned up if they're on the stack.
   138   MetadataOnStackMark md_on_stack;
   138   MetadataOnStackMark md_on_stack(true);
   139   HandleMark hm(thread);   // make sure any handles created are deleted
   139   HandleMark hm(thread);   // make sure any handles created are deleted
   140                            // before the stack walk again.
   140                            // before the stack walk again.
   141 
   141 
   142   for (int i = 0; i < _class_count; i++) {
   142   for (int i = 0; i < _class_count; i++) {
   143     redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
   143     redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  2824                                         &trace_name_printed);
  2824                                         &trace_name_printed);
  2825       }
  2825       }
  2826     }
  2826     }
  2827 
  2827 
  2828     // the previous versions' constant pool caches may need adjustment
  2828     // the previous versions' constant pool caches may need adjustment
  2829     PreviousVersionWalker pvw(_thread, ik);
  2829     for (InstanceKlass* pv_node = ik->previous_versions();
  2830     for (PreviousVersionNode * pv_node = pvw.next_previous_version();
  2830          pv_node != NULL;
  2831          pv_node != NULL; pv_node = pvw.next_previous_version()) {
  2831          pv_node = pv_node->previous_versions()) {
  2832       other_cp = pv_node->prev_constant_pool();
  2832       cp_cache = pv_node->constants()->cache();
  2833       cp_cache = other_cp->cache();
       
  2834       if (cp_cache != NULL) {
  2833       if (cp_cache != NULL) {
  2835         cp_cache->adjust_method_entries(_matching_old_methods,
  2834         cp_cache->adjust_method_entries(_matching_old_methods,
  2836                                         _matching_new_methods,
  2835                                         _matching_new_methods,
  2837                                         _matching_methods_length,
  2836                                         _matching_methods_length,
  2838                                         &trace_name_printed);
  2837                                         &trace_name_printed);
  2853              "should be replaced");
  2852              "should be replaced");
  2854     }
  2853     }
  2855   }
  2854   }
  2856 }
  2855 }
  2857 
  2856 
  2858 void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  2857 int VM_RedefineClasses::check_methods_and_mark_as_obsolete() {
  2859        BitMap *emcp_methods, int * emcp_method_count_p) {
  2858   int emcp_method_count = 0;
  2860   *emcp_method_count_p = 0;
       
  2861   int obsolete_count = 0;
  2859   int obsolete_count = 0;
  2862   int old_index = 0;
  2860   int old_index = 0;
  2863   for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  2861   for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  2864     Method* old_method = _matching_old_methods[j];
  2862     Method* old_method = _matching_old_methods[j];
  2865     Method* new_method = _matching_new_methods[j];
  2863     Method* new_method = _matching_new_methods[j];
  2929       //
  2927       //
  2930       // It looks like we will have to live with the limited savings
  2928       // It looks like we will have to live with the limited savings
  2931       // that we get from effectively overwriting the old methods
  2929       // that we get from effectively overwriting the old methods
  2932       // when the new methods are attached to the_class.
  2930       // when the new methods are attached to the_class.
  2933 
  2931 
  2934       // track which methods are EMCP for add_previous_version() call
  2932       // Count number of methods that are EMCP.  The method will be marked
  2935       emcp_methods->set_bit(old_index);
  2933       // old but not obsolete if it is EMCP.
  2936       (*emcp_method_count_p)++;
  2934       emcp_method_count++;
  2937 
  2935 
  2938       // An EMCP method is _not_ obsolete. An obsolete method has a
  2936       // An EMCP method is _not_ obsolete. An obsolete method has a
  2939       // different jmethodID than the current method. An EMCP method
  2937       // different jmethodID than the current method. An EMCP method
  2940       // has the same jmethodID as the current method. Having the
  2938       // has the same jmethodID as the current method. Having the
  2941       // same jmethodID for all EMCP versions of a method allows for
  2939       // same jmethodID for all EMCP versions of a method allows for
  2980     // EMCP methods.
  2978     // EMCP methods.
  2981     RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  2979     RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  2982                           old_method->name()->as_C_string(),
  2980                           old_method->name()->as_C_string(),
  2983                           old_method->signature()->as_C_string()));
  2981                           old_method->signature()->as_C_string()));
  2984   }
  2982   }
  2985   assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  2983   assert((emcp_method_count + obsolete_count) == _old_methods->length(),
  2986     "sanity check");
  2984     "sanity check");
  2987   RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  2985   RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", emcp_method_count,
  2988     obsolete_count));
  2986     obsolete_count));
       
  2987   return emcp_method_count;
  2989 }
  2988 }
  2990 
  2989 
  2991 // This internal class transfers the native function registration from old methods
  2990 // This internal class transfers the native function registration from old methods
  2992 // to new methods.  It is designed to handle both the simple case of unchanged
  2991 // to new methods.  It is designed to handle both the simple case of unchanged
  2993 // native methods and the complex cases of native method prefixes being added and/or
  2992 // native methods and the complex cases of native method prefixes being added and/or
  3377   // vtable's class and "the new class".
  3376   // vtable's class and "the new class".
  3378 
  3377 
  3379   old_constants->set_pool_holder(scratch_class());
  3378   old_constants->set_pool_holder(scratch_class());
  3380 #endif
  3379 #endif
  3381 
  3380 
  3382   // track which methods are EMCP for add_previous_version() call below
  3381   // track number of methods that are EMCP for add_previous_version() call below
  3383   BitMap emcp_methods(_old_methods->length());
  3382   int emcp_method_count = check_methods_and_mark_as_obsolete();
  3384   int emcp_method_count = 0;
       
  3385   emcp_methods.clear();  // clears 0..(length() - 1)
       
  3386   check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
       
  3387   transfer_old_native_function_registrations(the_class);
  3383   transfer_old_native_function_registrations(the_class);
  3388 
  3384 
  3389   // The class file bytes from before any retransformable agents mucked
  3385   // The class file bytes from before any retransformable agents mucked
  3390   // with them was cached on the scratch class, move to the_class.
  3386   // with them was cached on the scratch class, move to the_class.
  3391   // Note: we still want to do this if nothing needed caching since it
  3387   // Note: we still want to do this if nothing needed caching since it
  3469   the_class->set_enclosing_method_indices(
  3465   the_class->set_enclosing_method_indices(
  3470     scratch_class->enclosing_method_class_index(),
  3466     scratch_class->enclosing_method_class_index(),
  3471     scratch_class->enclosing_method_method_index());
  3467     scratch_class->enclosing_method_method_index());
  3472   scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  3468   scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  3473 
  3469 
       
  3470   the_class->set_has_been_redefined();
       
  3471 
  3474   // keep track of previous versions of this class
  3472   // keep track of previous versions of this class
  3475   the_class->add_previous_version(scratch_class, &emcp_methods,
  3473   the_class->add_previous_version(scratch_class, emcp_method_count);
  3476     emcp_method_count);
       
  3477 
  3474 
  3478   RC_TIMER_STOP(_timer_rsc_phase1);
  3475   RC_TIMER_STOP(_timer_rsc_phase1);
  3479   RC_TIMER_START(_timer_rsc_phase2);
  3476   RC_TIMER_START(_timer_rsc_phase2);
  3480 
  3477 
  3481   // Adjust constantpool caches and vtables for all classes
  3478   // Adjust constantpool caches and vtables for all classes