137 MetadataOnStackMark md_on_stack;
138 HandleMark hm(thread); // make sure any handles created are deleted
139 // before the stack walk again.
140
141 for (int i = 0; i < _class_count; i++) {
142 redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
143 ClassLoaderData* cld = _scratch_classes[i]->class_loader_data();
144 // Free the memory for this class at class unloading time. Not before
145 // because CMS might think this is still live.
146 cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]);
147 _scratch_classes[i] = NULL;
148 }
149
150 // Disable any dependent concurrent compilations
151 SystemDictionary::notice_modification();
152
153 // Set flag indicating that some invariants are no longer true.
154 // See jvmtiExport.hpp for detailed explanation.
155 JvmtiExport::set_has_redefined_a_class();
156
157 #ifdef ASSERT
158 SystemDictionary::classes_do(check_class, thread);
159 #endif
160 }
161
162 void VM_RedefineClasses::doit_epilogue() {
163 // Free os::malloc allocated memory.
164 os::free(_scratch_classes);
165
166 if (RC_TRACE_ENABLED(0x00000004)) {
167 // Used to have separate timers for "doit" and "all", but the timer
168 // overhead skewed the measurements.
169 jlong doit_time = _timer_rsc_phase1.milliseconds() +
170 _timer_rsc_phase2.milliseconds();
171 jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
172
173 RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
174 " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
175 _timer_vm_op_prologue.milliseconds(), doit_time));
176 RC_TRACE(0x00000004,
177 ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
178 _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
1547 case Bytecodes::_invokespecial : // fall through
1548 case Bytecodes::_invokestatic : // fall through
1549 case Bytecodes::_invokevirtual : // fall through
1550 case Bytecodes::_ldc_w : // fall through
1551 case Bytecodes::_ldc2_w : // fall through
1552 case Bytecodes::_multianewarray : // fall through
1553 case Bytecodes::_new : // fall through
1554 case Bytecodes::_putfield : // fall through
1555 case Bytecodes::_putstatic :
1556 {
1557 address p = bcp + 1;
1558 int cp_index = Bytes::get_Java_u2(p);
1559 int new_index = find_new_index(cp_index);
1560 if (new_index != 0) {
1561 // the original index is mapped so update w/ new value
1562 RC_TRACE_WITH_THREAD(0x00080000, THREAD,
1563 ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
1564 bcp, cp_index, new_index));
1565 // Rewriter::rewrite_method() uses put_native_u2() in this
1566 // situation because it is reusing the constant pool index
1567 // location for a native index into the constantPoolCache.
1568 // Since we are updating the constant pool index prior to
1569 // verification and constantPoolCache initialization, we
1570 // need to keep the new index in Java byte order.
1571 Bytes::put_Java_u2(p, new_index);
1572 }
1573 } break;
1574 }
1575 } // end for each bytecode
1576 } // end rewrite_cp_refs_in_method()
1577
1578
1579 // Rewrite constant pool references in the class_annotations field.
1580 bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
1581 instanceKlassHandle scratch_class, TRAPS) {
1582
1583 AnnotationArray* class_annotations = scratch_class->class_annotations();
1584 if (class_annotations == NULL || class_annotations->length() == 0) {
1585 // no class_annotations so nothing to do
1586 return true;
1587 }
1588
1589 RC_TRACE_WITH_THREAD(0x02000000, THREAD,
3354 int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
3355 java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
3356
3357 if (class_oop != _the_class_oop) {
3358 // _the_class_oop count is printed at end of redefine_single_class()
3359 RC_TRACE_WITH_THREAD(0x00000008, THREAD,
3360 ("updated count in subclass=%s to %d", ik->external_name(), new_count));
3361 }
3362
3363 for (Klass *subk = ik->subklass(); subk != NULL;
3364 subk = subk->next_sibling()) {
3365 if (subk->oop_is_instance()) {
3366 // Only update instanceKlasses
3367 InstanceKlass *subik = (InstanceKlass*)subk;
3368 // recursively do subclasses of the current subclass
3369 increment_class_counter(subik, THREAD);
3370 }
3371 }
3372 }
3373
3374 #ifndef PRODUCT
3375 void VM_RedefineClasses::check_class(Klass* k_oop,
3376 ClassLoaderData* initiating_loader,
3377 TRAPS) {
3378 Klass *k = k_oop;
3379 if (k->oop_is_instance()) {
3380 HandleMark hm(THREAD);
3381 InstanceKlass *ik = (InstanceKlass *) k;
3382
3383 if (ik->vtable_length() > 0) {
3384 ResourceMark rm(THREAD);
3385 if (!ik->vtable()->check_no_old_entries()) {
3386 tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
3387 ik->vtable()->dump_vtable();
3388 assert(false, "OLD method found");
3389 }
3390 }
3391 if (ik->itable_length() > 0) {
3392 ResourceMark rm(THREAD);
3393 if (!ik->itable()->check_no_old_entries()) {
3394 tty->print_cr("klassItable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
3395 assert(false, "OLD method found");
3396 }
3397 }
3398 // Check that the constant pool cache has no deleted entries.
3399 if (ik->constants() != NULL &&
3400 ik->constants()->cache() != NULL &&
3401 !ik->constants()->cache()->check_no_old_entries()) {
3402 tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
3403 assert(false, "OLD method found");
3404 }
3405 }
3406 }
3407
3408 void VM_RedefineClasses::dump_methods() {
3409 int j;
3410 tty->print_cr("_old_methods --");
3411 for (j = 0; j < _old_methods->length(); ++j) {
3412 Method* m = _old_methods->at(j);
3413 tty->print("%4d (%5d) ", j, m->vtable_index());
3414 m->access_flags().print_on(tty);
3415 tty->print(" -- ");
3416 m->print_name(tty);
3417 tty->cr();
3418 }
3419 tty->print_cr("_new_methods --");
3420 for (j = 0; j < _new_methods->length(); ++j) {
3421 Method* m = _new_methods->at(j);
3422 tty->print("%4d (%5d) ", j, m->vtable_index());
3423 m->access_flags().print_on(tty);
3424 tty->print(" -- ");
3425 m->print_name(tty);
3426 tty->cr();
3427 }
3428 tty->print_cr("_matching_(old/new)_methods --");
3429 for (j = 0; j < _matching_methods_length; ++j) {
3430 Method* m = _matching_old_methods[j];
3431 tty->print("%4d (%5d) ", j, m->vtable_index());
3432 m->access_flags().print_on(tty);
3433 tty->print(" -- ");
3434 m->print_name(tty);
3435 tty->cr();
3436 m = _matching_new_methods[j];
3437 tty->print(" (%5d) ", m->vtable_index());
3438 m->access_flags().print_on(tty);
3439 tty->cr();
3440 }
3441 tty->print_cr("_deleted_methods --");
3442 for (j = 0; j < _deleted_methods_length; ++j) {
3443 Method* m = _deleted_methods[j];
3444 tty->print("%4d (%5d) ", j, m->vtable_index());
3445 m->access_flags().print_on(tty);
3446 tty->print(" -- ");
3447 m->print_name(tty);
3448 tty->cr();
3449 }
3450 tty->print_cr("_added_methods --");
3451 for (j = 0; j < _added_methods_length; ++j) {
3452 Method* m = _added_methods[j];
3453 tty->print("%4d (%5d) ", j, m->vtable_index());
3454 m->access_flags().print_on(tty);
3455 tty->print(" -- ");
3456 m->print_name(tty);
3457 tty->cr();
3458 }
3459 }
3460 #endif
|
137 MetadataOnStackMark md_on_stack;
138 HandleMark hm(thread); // make sure any handles created are deleted
139 // before the stack walk again.
140
141 for (int i = 0; i < _class_count; i++) {
142 redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
143 ClassLoaderData* cld = _scratch_classes[i]->class_loader_data();
144 // Free the memory for this class at class unloading time. Not before
145 // because CMS might think this is still live.
146 cld->add_to_deallocate_list((InstanceKlass*)_scratch_classes[i]);
147 _scratch_classes[i] = NULL;
148 }
149
150 // Disable any dependent concurrent compilations
151 SystemDictionary::notice_modification();
152
153 // Set flag indicating that some invariants are no longer true.
154 // See jvmtiExport.hpp for detailed explanation.
155 JvmtiExport::set_has_redefined_a_class();
156
157 // check_class() is optionally called for product bits, but is
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 }
166 #endif
167 }
168
169 void VM_RedefineClasses::doit_epilogue() {
170 // Free os::malloc allocated memory.
171 os::free(_scratch_classes);
172
173 if (RC_TRACE_ENABLED(0x00000004)) {
174 // Used to have separate timers for "doit" and "all", but the timer
175 // overhead skewed the measurements.
176 jlong doit_time = _timer_rsc_phase1.milliseconds() +
177 _timer_rsc_phase2.milliseconds();
178 jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
179
180 RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
181 " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
182 _timer_vm_op_prologue.milliseconds(), doit_time));
183 RC_TRACE(0x00000004,
184 ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
185 _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
1554 case Bytecodes::_invokespecial : // fall through
1555 case Bytecodes::_invokestatic : // fall through
1556 case Bytecodes::_invokevirtual : // fall through
1557 case Bytecodes::_ldc_w : // fall through
1558 case Bytecodes::_ldc2_w : // fall through
1559 case Bytecodes::_multianewarray : // fall through
1560 case Bytecodes::_new : // fall through
1561 case Bytecodes::_putfield : // fall through
1562 case Bytecodes::_putstatic :
1563 {
1564 address p = bcp + 1;
1565 int cp_index = Bytes::get_Java_u2(p);
1566 int new_index = find_new_index(cp_index);
1567 if (new_index != 0) {
1568 // the original index is mapped so update w/ new value
1569 RC_TRACE_WITH_THREAD(0x00080000, THREAD,
1570 ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
1571 bcp, cp_index, new_index));
1572 // Rewriter::rewrite_method() uses put_native_u2() in this
1573 // situation because it is reusing the constant pool index
1574 // location for a native index into the ConstantPoolCache.
1575 // Since we are updating the constant pool index prior to
1576 // verification and ConstantPoolCache initialization, we
1577 // need to keep the new index in Java byte order.
1578 Bytes::put_Java_u2(p, new_index);
1579 }
1580 } break;
1581 }
1582 } // end for each bytecode
1583 } // end rewrite_cp_refs_in_method()
1584
1585
1586 // Rewrite constant pool references in the class_annotations field.
1587 bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
1588 instanceKlassHandle scratch_class, TRAPS) {
1589
1590 AnnotationArray* class_annotations = scratch_class->class_annotations();
1591 if (class_annotations == NULL || class_annotations->length() == 0) {
1592 // no class_annotations so nothing to do
1593 return true;
1594 }
1595
1596 RC_TRACE_WITH_THREAD(0x02000000, THREAD,
3361 int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
3362 java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
3363
3364 if (class_oop != _the_class_oop) {
3365 // _the_class_oop count is printed at end of redefine_single_class()
3366 RC_TRACE_WITH_THREAD(0x00000008, THREAD,
3367 ("updated count in subclass=%s to %d", ik->external_name(), new_count));
3368 }
3369
3370 for (Klass *subk = ik->subklass(); subk != NULL;
3371 subk = subk->next_sibling()) {
3372 if (subk->oop_is_instance()) {
3373 // Only update instanceKlasses
3374 InstanceKlass *subik = (InstanceKlass*)subk;
3375 // recursively do subclasses of the current subclass
3376 increment_class_counter(subik, THREAD);
3377 }
3378 }
3379 }
3380
3381 void VM_RedefineClasses::check_class(Klass* k_oop,
3382 ClassLoaderData* initiating_loader,
3383 TRAPS) {
3384 Klass *k = k_oop;
3385 if (k->oop_is_instance()) {
3386 HandleMark hm(THREAD);
3387 InstanceKlass *ik = (InstanceKlass *) k;
3388 bool no_old_methods = true; // be optimistic
3389 ResourceMark rm(THREAD);
3390
3391 // a vtable should never contain old or obsolete methods
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()));
3399 ik->vtable()->dump_vtable();
3400 }
3401 no_old_methods = false;
3402 }
3403
3404 // an itable should never contain old or obsolete methods
3405 if (ik->itable_length() > 0 &&
3406 !ik->itable()->check_no_old_or_obsolete_entries()) {
3407 if (RC_TRACE_ENABLED(0x00004000)) {
3408 RC_TRACE_WITH_THREAD(0x00004000, THREAD,
3409 ("klassItable::check_no_old_or_obsolete_entries failure"
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
3418 if (ik->constants() != NULL &&
3419 ik->constants()->cache() != NULL &&
3420 !ik->constants()->cache()->check_no_old_or_obsolete_entries()) {
3421 if (RC_TRACE_ENABLED(0x00004000)) {
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");
3439 }
3440 }
3441 }
3442
3443 void VM_RedefineClasses::dump_methods() {
3444 int j;
3445 RC_TRACE(0x00004000, ("_old_methods --"));
3446 for (j = 0; j < _old_methods->length(); ++j) {
3447 Method* m = _old_methods->at(j);
3448 RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
3449 m->access_flags().print_on(tty);
3450 tty->print(" -- ");
3451 m->print_name(tty);
3452 tty->cr();
3453 }
3454 RC_TRACE(0x00004000, ("_new_methods --"));
3455 for (j = 0; j < _new_methods->length(); ++j) {
3456 Method* m = _new_methods->at(j);
3457 RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
3458 m->access_flags().print_on(tty);
3459 tty->print(" -- ");
3460 m->print_name(tty);
3461 tty->cr();
3462 }
3463 RC_TRACE(0x00004000, ("_matching_(old/new)_methods --"));
3464 for (j = 0; j < _matching_methods_length; ++j) {
3465 Method* m = _matching_old_methods[j];
3466 RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
3467 m->access_flags().print_on(tty);
3468 tty->print(" -- ");
3469 m->print_name(tty);
3470 tty->cr();
3471 m = _matching_new_methods[j];
3472 RC_TRACE_NO_CR(0x00004000, (" (%5d) ", m->vtable_index()));
3473 m->access_flags().print_on(tty);
3474 tty->cr();
3475 }
3476 RC_TRACE(0x00004000, ("_deleted_methods --"));
3477 for (j = 0; j < _deleted_methods_length; ++j) {
3478 Method* m = _deleted_methods[j];
3479 RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
3480 m->access_flags().print_on(tty);
3481 tty->print(" -- ");
3482 m->print_name(tty);
3483 tty->cr();
3484 }
3485 RC_TRACE(0x00004000, ("_added_methods --"));
3486 for (j = 0; j < _added_methods_length; ++j) {
3487 Method* m = _added_methods[j];
3488 RC_TRACE_NO_CR(0x00004000, ("%4d (%5d) ", j, m->vtable_index()));
3489 m->access_flags().print_on(tty);
3490 tty->print(" -- ");
3491 m->print_name(tty);
3492 tty->cr();
3493 }
3494 }
|