hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp
changeset 15591 b8aa0577f137
parent 15446 5ea56212959f
child 15601 df8faef6efaf
equal deleted inserted replaced
15469:7719efe7b23d 15591:b8aa0577f137
   152 
   152 
   153   // Set flag indicating that some invariants are no longer true.
   153   // Set flag indicating that some invariants are no longer true.
   154   // See jvmtiExport.hpp for detailed explanation.
   154   // See jvmtiExport.hpp for detailed explanation.
   155   JvmtiExport::set_has_redefined_a_class();
   155   JvmtiExport::set_has_redefined_a_class();
   156 
   156 
   157 #ifdef ASSERT
   157 // check_class() is optionally called for product bits, but is
   158   SystemDictionary::classes_do(check_class, thread);
   158 // always called for non-product bits.
       
   159 #ifdef PRODUCT
       
   160   if (RC_TRACE_ENABLED(0x00004000)) {
       
   161 #endif
       
   162     RC_TRACE_WITH_THREAD(0x00004000, thread, ("calling check_class"));
       
   163     SystemDictionary::classes_do(check_class, thread);
       
   164 #ifdef PRODUCT
       
   165   }
   159 #endif
   166 #endif
   160 }
   167 }
   161 
   168 
   162 void VM_RedefineClasses::doit_epilogue() {
   169 void VM_RedefineClasses::doit_epilogue() {
   163   // Free os::malloc allocated memory.
   170   // Free os::malloc allocated memory.
  1562           RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  1569           RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  1563             ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  1570             ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  1564             bcp, cp_index, new_index));
  1571             bcp, cp_index, new_index));
  1565           // Rewriter::rewrite_method() uses put_native_u2() in this
  1572           // Rewriter::rewrite_method() uses put_native_u2() in this
  1566           // situation because it is reusing the constant pool index
  1573           // situation because it is reusing the constant pool index
  1567           // location for a native index into the constantPoolCache.
  1574           // location for a native index into the ConstantPoolCache.
  1568           // Since we are updating the constant pool index prior to
  1575           // Since we are updating the constant pool index prior to
  1569           // verification and constantPoolCache initialization, we
  1576           // verification and ConstantPoolCache initialization, we
  1570           // need to keep the new index in Java byte order.
  1577           // need to keep the new index in Java byte order.
  1571           Bytes::put_Java_u2(p, new_index);
  1578           Bytes::put_Java_u2(p, new_index);
  1572         }
  1579         }
  1573       } break;
  1580       } break;
  1574     }
  1581     }
  3369       increment_class_counter(subik, THREAD);
  3376       increment_class_counter(subik, THREAD);
  3370     }
  3377     }
  3371   }
  3378   }
  3372 }
  3379 }
  3373 
  3380 
  3374 #ifndef PRODUCT
       
  3375 void VM_RedefineClasses::check_class(Klass* k_oop,
  3381 void VM_RedefineClasses::check_class(Klass* k_oop,
  3376                                      ClassLoaderData* initiating_loader,
  3382                                      ClassLoaderData* initiating_loader,
  3377                                      TRAPS) {
  3383                                      TRAPS) {
  3378   Klass *k = k_oop;
  3384   Klass *k = k_oop;
  3379   if (k->oop_is_instance()) {
  3385   if (k->oop_is_instance()) {
  3380     HandleMark hm(THREAD);
  3386     HandleMark hm(THREAD);
  3381     InstanceKlass *ik = (InstanceKlass *) k;
  3387     InstanceKlass *ik = (InstanceKlass *) k;
  3382 
  3388     bool no_old_methods = true;  // be optimistic
  3383     if (ik->vtable_length() > 0) {
  3389     ResourceMark rm(THREAD);
  3384       ResourceMark rm(THREAD);
  3390 
  3385       if (!ik->vtable()->check_no_old_entries()) {
  3391     // a vtable should never contain old or obsolete methods
  3386         tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  3392     if (ik->vtable_length() > 0 &&
       
  3393         !ik->vtable()->check_no_old_or_obsolete_entries()) {
       
  3394       if (RC_TRACE_ENABLED(0x00004000)) {
       
  3395         RC_TRACE_WITH_THREAD(0x00004000, THREAD,
       
  3396           ("klassVtable::check_no_old_or_obsolete_entries failure"
       
  3397            " -- OLD or OBSOLETE method found -- class: %s",
       
  3398            ik->signature_name()));
  3387         ik->vtable()->dump_vtable();
  3399         ik->vtable()->dump_vtable();
  3388         assert(false, "OLD method found");
  3400       }
  3389       }
  3401       no_old_methods = false;
  3390     }
  3402     }
  3391     if (ik->itable_length() > 0) {
  3403 
  3392       ResourceMark rm(THREAD);
  3404     // an itable should never contain old or obsolete methods
  3393       if (!ik->itable()->check_no_old_entries()) {
  3405     if (ik->itable_length() > 0 &&
  3394         tty->print_cr("klassItable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  3406         !ik->itable()->check_no_old_or_obsolete_entries()) {
  3395         assert(false, "OLD method found");
  3407       if (RC_TRACE_ENABLED(0x00004000)) {
  3396       }
  3408         RC_TRACE_WITH_THREAD(0x00004000, THREAD,
  3397     }
  3409           ("klassItable::check_no_old_or_obsolete_entries failure"
  3398     // Check that the constant pool cache has no deleted entries.
  3410            " -- OLD or OBSOLETE method found -- class: %s",
       
  3411            ik->signature_name()));
       
  3412         ik->itable()->dump_itable();
       
  3413       }
       
  3414       no_old_methods = false;
       
  3415     }
       
  3416 
       
  3417     // the constant pool cache should never contain old or obsolete methods
  3399     if (ik->constants() != NULL &&
  3418     if (ik->constants() != NULL &&
  3400         ik->constants()->cache() != NULL &&
  3419         ik->constants()->cache() != NULL &&
  3401        !ik->constants()->cache()->check_no_old_entries()) {
  3420         !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
  3402       tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  3421       if (RC_TRACE_ENABLED(0x00004000)) {
  3403       assert(false, "OLD method found");
  3422         RC_TRACE_WITH_THREAD(0x00004000, THREAD,
       
  3423           ("cp-cache::check_no_old_or_obsolete_entries failure"
       
  3424            " -- OLD or OBSOLETE method found -- class: %s",
       
  3425            ik->signature_name()));
       
  3426         ik->constants()->cache()->dump_cache();
       
  3427       }
       
  3428       no_old_methods = false;
       
  3429     }
       
  3430 
       
  3431     if (!no_old_methods) {
       
  3432       if (RC_TRACE_ENABLED(0x00004000)) {
       
  3433         dump_methods();
       
  3434       } else {
       
  3435         tty->print_cr("INFO: use the '-XX:TraceRedefineClasses=16384' option "
       
  3436           "to see more info about the following guarantee() failure.");
       
  3437       }
       
  3438       guarantee(false, "OLD and/or OBSOLETE method(s) found");
  3404     }
  3439     }
  3405   }
  3440   }
  3406 }
  3441 }
  3407 
  3442 
  3408 void VM_RedefineClasses::dump_methods() {
  3443 void VM_RedefineClasses::dump_methods() {
  3409         int j;
  3444   int j;
  3410         tty->print_cr("_old_methods --");
  3445   RC_TRACE(0x00004000, ("_old_methods --"));
  3411         for (j = 0; j < _old_methods->length(); ++j) {
  3446   for (j = 0; j < _old_methods->length(); ++j) {
  3412           Method* m = _old_methods->at(j);
  3447     Method* m = _old_methods->at(j);
  3413           tty->print("%4d  (%5d)  ", j, m->vtable_index());
  3448     RC_TRACE_NO_CR(0x00004000, ("%4d  (%5d)  ", j, m->vtable_index()));
  3414           m->access_flags().print_on(tty);
  3449     m->access_flags().print_on(tty);
  3415           tty->print(" --  ");
  3450     tty->print(" --  ");
  3416           m->print_name(tty);
  3451     m->print_name(tty);
  3417           tty->cr();
  3452     tty->cr();
  3418         }
  3453   }
  3419         tty->print_cr("_new_methods --");
  3454   RC_TRACE(0x00004000, ("_new_methods --"));
  3420         for (j = 0; j < _new_methods->length(); ++j) {
  3455   for (j = 0; j < _new_methods->length(); ++j) {
  3421           Method* m = _new_methods->at(j);
  3456     Method* m = _new_methods->at(j);
  3422           tty->print("%4d  (%5d)  ", j, m->vtable_index());
  3457     RC_TRACE_NO_CR(0x00004000, ("%4d  (%5d)  ", j, m->vtable_index()));
  3423           m->access_flags().print_on(tty);
  3458     m->access_flags().print_on(tty);
  3424           tty->print(" --  ");
  3459     tty->print(" --  ");
  3425           m->print_name(tty);
  3460     m->print_name(tty);
  3426           tty->cr();
  3461     tty->cr();
  3427         }
  3462   }
  3428         tty->print_cr("_matching_(old/new)_methods --");
  3463   RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
  3429         for (j = 0; j < _matching_methods_length; ++j) {
  3464   for (j = 0; j < _matching_methods_length; ++j) {
  3430           Method* m = _matching_old_methods[j];
  3465     Method* m = _matching_old_methods[j];
  3431           tty->print("%4d  (%5d)  ", j, m->vtable_index());
  3466     RC_TRACE_NO_CR(0x00004000, ("%4d  (%5d)  ", j, m->vtable_index()));
  3432           m->access_flags().print_on(tty);
  3467     m->access_flags().print_on(tty);
  3433           tty->print(" --  ");
  3468     tty->print(" --  ");
  3434           m->print_name(tty);
  3469     m->print_name(tty);
  3435           tty->cr();
  3470     tty->cr();
  3436           m = _matching_new_methods[j];
  3471     m = _matching_new_methods[j];
  3437           tty->print("      (%5d)  ", m->vtable_index());
  3472     RC_TRACE_NO_CR(0x00004000, ("      (%5d)  ", m->vtable_index()));
  3438           m->access_flags().print_on(tty);
  3473     m->access_flags().print_on(tty);
  3439           tty->cr();
  3474     tty->cr();
  3440         }
  3475   }
  3441         tty->print_cr("_deleted_methods --");
  3476   RC_TRACE(0x00004000, ("_deleted_methods --"));
  3442         for (j = 0; j < _deleted_methods_length; ++j) {
  3477   for (j = 0; j < _deleted_methods_length; ++j) {
  3443           Method* m = _deleted_methods[j];
  3478     Method* m = _deleted_methods[j];
  3444           tty->print("%4d  (%5d)  ", j, m->vtable_index());
  3479     RC_TRACE_NO_CR(0x00004000, ("%4d  (%5d)  ", j, m->vtable_index()));
  3445           m->access_flags().print_on(tty);
  3480     m->access_flags().print_on(tty);
  3446           tty->print(" --  ");
  3481     tty->print(" --  ");
  3447           m->print_name(tty);
  3482     m->print_name(tty);
  3448           tty->cr();
  3483     tty->cr();
  3449         }
  3484   }
  3450         tty->print_cr("_added_methods --");
  3485   RC_TRACE(0x00004000, ("_added_methods --"));
  3451         for (j = 0; j < _added_methods_length; ++j) {
  3486   for (j = 0; j < _added_methods_length; ++j) {
  3452           Method* m = _added_methods[j];
  3487     Method* m = _added_methods[j];
  3453           tty->print("%4d  (%5d)  ", j, m->vtable_index());
  3488     RC_TRACE_NO_CR(0x00004000, ("%4d  (%5d)  ", j, m->vtable_index()));
  3454           m->access_flags().print_on(tty);
  3489     m->access_flags().print_on(tty);
  3455           tty->print(" --  ");
  3490     tty->print(" --  ");
  3456           m->print_name(tty);
  3491     m->print_name(tty);
  3457           tty->cr();
  3492     tty->cr();
  3458         }
  3493   }
  3459 }
  3494 }
  3460 #endif