1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
438 Method* new_method, bool * trace_name_printed) {
439
440 if (is_vfinal()) {
441 // virtual and final so _f2 contains method ptr instead of vtable index
442 if (f2_as_vfinal_method() == old_method) {
443 // match old_method so need an update
444 // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
445 _f2 = (intptr_t)new_method;
446 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
447 if (!(*trace_name_printed)) {
448 // RC_TRACE_MESG macro has an embedded ResourceMark
449 RC_TRACE_MESG(("adjust: name=%s",
450 old_method->method_holder()->external_name()));
451 *trace_name_printed = true;
452 }
453 // RC_TRACE macro has an embedded ResourceMark
454 RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
455 new_method->name()->as_C_string(),
456 new_method->signature()->as_C_string()));
457 }
458
459 return true;
460 }
461
462 // f1() is not used with virtual entries so bail out
463 return false;
464 }
465
466 if (_f1 == NULL) {
467 // NULL f1() means this is a virtual entry so bail out
468 // We are assuming that the vtable index does not need change.
469 return false;
470 }
471
472 if (_f1 == old_method) {
473 _f1 = new_method;
474 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
475 if (!(*trace_name_printed)) {
476 // RC_TRACE_MESG macro has an embedded ResourceMark
477 RC_TRACE_MESG(("adjust: name=%s",
478 old_method->method_holder()->external_name()));
479 *trace_name_printed = true;
480 }
481 // RC_TRACE macro has an embedded ResourceMark
482 RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
483 new_method->name()->as_C_string(),
484 new_method->signature()->as_C_string()));
485 }
486
487 return true;
488 }
489
490 return false;
491 }
492
493 // a constant pool cache entry should never contain old or obsolete methods
494 bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
495 if (is_vfinal()) {
496 // virtual and final so _f2 contains method ptr instead of vtable index
497 Metadata* f2 = (Metadata*)_f2;
498 // Return false if _f2 refers to an old or an obsolete method.
499 // _f2 == NULL || !_f2->is_method() are just as unexpected here.
500 return (f2 != NULL NOT_PRODUCT(&& f2->is_valid()) && f2->is_method() &&
501 !((Method*)f2)->is_old() && !((Method*)f2)->is_obsolete());
502 } else if (_f1 == NULL ||
503 (NOT_PRODUCT(_f1->is_valid() &&) !_f1->is_method())) {
504 // _f1 == NULL || !_f1->is_method() are OK here
505 return true;
506 }
507 // return false if _f1 refers to a non-deleted old or obsolete method
508 return (NOT_PRODUCT(_f1->is_valid() &&) _f1->is_method() &&
509 (f1_as_method()->is_deleted() ||
510 (!f1_as_method()->is_old() && !f1_as_method()->is_obsolete())));
511 }
512
513 bool ConstantPoolCacheEntry::is_interesting_method_entry(Klass* k) {
514 if (!is_method_entry()) {
515 // not a method entry so not interesting by default
516 return false;
517 }
518
519 Method* m = NULL;
520 if (is_vfinal()) {
521 // virtual and final so _f2 contains method ptr instead of vtable index
522 m = f2_as_vfinal_method();
523 } else if (is_f1_null()) {
524 // NULL _f1 means this is a virtual entry so also not interesting
525 return false;
526 } else {
527 if (!(_f1->is_method())) {
528 // _f1 can also contain a Klass* for an interface
529 return false;
530 }
531 m = f1_as_method();
532 }
533
534 assert(m != NULL && m->is_method(), "sanity check");
535 if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
536 // robustness for above sanity checks or method is not in
537 // the interesting class
538 return false;
539 }
540
541 // the method is in the interesting class so the entry is interesting
542 return true;
543 }
544 #endif // INCLUDE_JVMTI
545
546 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
547 // print separator
548 if (index == 0) st->print_cr(" -------------");
549 // print entry
550 st->print("%3d ("PTR_FORMAT") ", index, (intptr_t)this);
551 st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(),
552 constant_pool_index());
553 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_f1);
554 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_f2);
555 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_flags);
556 st->print_cr(" -------------");
557 }
558
559 void ConstantPoolCacheEntry::verify(outputStream* st) const {
560 // not implemented yet
561 }
562
610 }
611 }
612 }
613
614 #if INCLUDE_JVMTI
615 // RedefineClasses() API support:
616 // If any entry of this ConstantPoolCache points to any of
617 // old_methods, replace it with the corresponding new_method.
618 void ConstantPoolCache::adjust_method_entries(Method** old_methods, Method** new_methods,
619 int methods_length, bool * trace_name_printed) {
620
621 if (methods_length == 0) {
622 // nothing to do if there are no methods
623 return;
624 }
625
626 // get shorthand for the interesting class
627 Klass* old_holder = old_methods[0]->method_holder();
628
629 for (int i = 0; i < length(); i++) {
630 if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
631 // skip uninteresting methods
632 continue;
633 }
634
635 // The ConstantPoolCache contains entries for several different
636 // things, but we only care about methods. In fact, we only care
637 // about methods in the same class as the one that contains the
638 // old_methods. At this point, we have an interesting entry.
639
640 for (int j = 0; j < methods_length; j++) {
641 Method* old_method = old_methods[j];
642 Method* new_method = new_methods[j];
643
644 if (entry_at(i)->adjust_method_entry(old_method, new_method,
645 trace_name_printed)) {
646 // current old_method matched this entry and we updated it so
647 // break out and get to the next interesting entry if there one
648 break;
649 }
650 }
651 }
652 }
653
654 // the constant pool cache should never contain old or obsolete methods
655 bool ConstantPoolCache::check_no_old_or_obsolete_entries() {
656 for (int i = 1; i < length(); i++) {
657 if (entry_at(i)->is_interesting_method_entry(NULL) &&
658 !entry_at(i)->check_no_old_or_obsolete_entries()) {
659 return false;
660 }
661 }
662 return true;
663 }
664
665 void ConstantPoolCache::dump_cache() {
666 for (int i = 1; i < length(); i++) {
667 if (entry_at(i)->is_interesting_method_entry(NULL)) {
668 entry_at(i)->print(tty, i);
669 }
670 }
671 }
672 #endif // INCLUDE_JVMTI
673
674
675 // Printing
676
677 void ConstantPoolCache::print_on(outputStream* st) const {
678 assert(is_constantPoolCache(), "obj must be constant pool cache");
679 st->print_cr("%s", internal_name());
680 // print constant pool cache entries
681 for (int i = 0; i < length(); i++) entry_at(i)->print(st, i);
682 }
683
684 void ConstantPoolCache::print_value_on(outputStream* st) const {
685 assert(is_constantPoolCache(), "obj must be constant pool cache");
686 st->print("cache [%d]", length());
687 print_address_on(st);
|
1 /*
2 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
438 Method* new_method, bool * trace_name_printed) {
439
440 if (is_vfinal()) {
441 // virtual and final so _f2 contains method ptr instead of vtable index
442 if (f2_as_vfinal_method() == old_method) {
443 // match old_method so need an update
444 // NOTE: can't use set_f2_as_vfinal_method as it asserts on different values
445 _f2 = (intptr_t)new_method;
446 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
447 if (!(*trace_name_printed)) {
448 // RC_TRACE_MESG macro has an embedded ResourceMark
449 RC_TRACE_MESG(("adjust: name=%s",
450 old_method->method_holder()->external_name()));
451 *trace_name_printed = true;
452 }
453 // RC_TRACE macro has an embedded ResourceMark
454 RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
455 new_method->name()->as_C_string(),
456 new_method->signature()->as_C_string()));
457 }
458 return true;
459 }
460
461 // f1() is not used with virtual entries so bail out
462 return false;
463 }
464
465 if (_f1 == NULL) {
466 // NULL f1() means this is a virtual entry so bail out
467 // We are assuming that the vtable index does not need change.
468 return false;
469 }
470
471 if (_f1 == old_method) {
472 _f1 = new_method;
473 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
474 if (!(*trace_name_printed)) {
475 // RC_TRACE_MESG macro has an embedded ResourceMark
476 RC_TRACE_MESG(("adjust: name=%s",
477 old_method->method_holder()->external_name()));
478 *trace_name_printed = true;
479 }
480 // RC_TRACE macro has an embedded ResourceMark
481 RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
482 new_method->name()->as_C_string(),
483 new_method->signature()->as_C_string()));
484 }
485 return true;
486 }
487
488 return false;
489 }
490
491 // a constant pool cache entry should never contain old or obsolete methods
492 bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
493 if (is_vfinal()) {
494 // virtual and final so _f2 contains method ptr instead of vtable index
495 Metadata* f2 = (Metadata*)_f2;
496 // Return false if _f2 refers to an old or an obsolete method.
497 // _f2 == NULL || !_f2->is_method() are just as unexpected here.
498 return (f2 != NULL NOT_PRODUCT(&& f2->is_valid()) && f2->is_method() &&
499 !((Method*)f2)->is_old() && !((Method*)f2)->is_obsolete());
500 } else if (_f1 == NULL ||
501 (NOT_PRODUCT(_f1->is_valid() &&) !_f1->is_method())) {
502 // _f1 == NULL || !_f1->is_method() are OK here
503 return true;
504 }
505 // return false if _f1 refers to a non-deleted old or obsolete method
506 return (NOT_PRODUCT(_f1->is_valid() &&) _f1->is_method() &&
507 (f1_as_method()->is_deleted() ||
508 (!f1_as_method()->is_old() && !f1_as_method()->is_obsolete())));
509 }
510
511 Method* ConstantPoolCacheEntry::get_interesting_method_entry(Klass* k) {
512 if (!is_method_entry()) {
513 // not a method entry so not interesting by default
514 return NULL;
515 }
516 Method* m = NULL;
517 if (is_vfinal()) {
518 // virtual and final so _f2 contains method ptr instead of vtable index
519 m = f2_as_vfinal_method();
520 } else if (is_f1_null()) {
521 // NULL _f1 means this is a virtual entry so also not interesting
522 return NULL;
523 } else {
524 if (!(_f1->is_method())) {
525 // _f1 can also contain a Klass* for an interface
526 return NULL;
527 }
528 m = f1_as_method();
529 }
530 assert(m != NULL && m->is_method(), "sanity check");
531 if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
532 // robustness for above sanity checks or method is not in
533 // the interesting class
534 return NULL;
535 }
536 // the method is in the interesting class so the entry is interesting
537 return m;
538 }
539 #endif // INCLUDE_JVMTI
540
541 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
542 // print separator
543 if (index == 0) st->print_cr(" -------------");
544 // print entry
545 st->print("%3d ("PTR_FORMAT") ", index, (intptr_t)this);
546 st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(),
547 constant_pool_index());
548 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_f1);
549 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_f2);
550 st->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_flags);
551 st->print_cr(" -------------");
552 }
553
554 void ConstantPoolCacheEntry::verify(outputStream* st) const {
555 // not implemented yet
556 }
557
605 }
606 }
607 }
608
609 #if INCLUDE_JVMTI
610 // RedefineClasses() API support:
611 // If any entry of this ConstantPoolCache points to any of
612 // old_methods, replace it with the corresponding new_method.
613 void ConstantPoolCache::adjust_method_entries(Method** old_methods, Method** new_methods,
614 int methods_length, bool * trace_name_printed) {
615
616 if (methods_length == 0) {
617 // nothing to do if there are no methods
618 return;
619 }
620
621 // get shorthand for the interesting class
622 Klass* old_holder = old_methods[0]->method_holder();
623
624 for (int i = 0; i < length(); i++) {
625 if (entry_at(i)->get_interesting_method_entry(old_holder) == NULL) {
626 // skip uninteresting methods
627 continue;
628 }
629
630 // The ConstantPoolCache contains entries for several different
631 // things, but we only care about methods. In fact, we only care
632 // about methods in the same class as the one that contains the
633 // old_methods. At this point, we have an interesting entry.
634
635 for (int j = 0; j < methods_length; j++) {
636 Method* old_method = old_methods[j];
637 Method* new_method = new_methods[j];
638
639 if (entry_at(i)->adjust_method_entry(old_method, new_method,
640 trace_name_printed)) {
641 // current old_method matched this entry and we updated it so
642 // break out and get to the next interesting entry if there one
643 break;
644 }
645 }
646 }
647 }
648
649 // If any entry of this ConstantPoolCache points to any of
650 // old_methods, replace it with the corresponding new_method.
651 void ConstantPoolCache::adjust_method_entries(InstanceKlass* holder, bool * trace_name_printed) {
652 for (int i = 0; i < length(); i++) {
653 ConstantPoolCacheEntry* entry = entry_at(i);
654 Method* old_method = entry->get_interesting_method_entry(holder);
655 if (old_method == NULL || !old_method->is_old()) {
656 continue; // skip uninteresting entries
657 }
658 if (old_method->is_deleted()) {
659 // clean up entries with deleted methods
660 entry->initialize_entry(entry->constant_pool_index());
661 continue;
662 }
663 Method* new_method = holder->method_with_idnum(old_method->orig_method_idnum());
664
665 assert(new_method != NULL, "method_with_idnum() should not be NULL");
666 assert(old_method != new_method, "sanity check");
667
668 entry_at(i)->adjust_method_entry(old_method, new_method, trace_name_printed);
669 }
670 }
671
672 // the constant pool cache should never contain old or obsolete methods
673 bool ConstantPoolCache::check_no_old_or_obsolete_entries() {
674 for (int i = 1; i < length(); i++) {
675 if (entry_at(i)->get_interesting_method_entry(NULL) != NULL &&
676 !entry_at(i)->check_no_old_or_obsolete_entries()) {
677 return false;
678 }
679 }
680 return true;
681 }
682
683 void ConstantPoolCache::dump_cache() {
684 for (int i = 1; i < length(); i++) {
685 if (entry_at(i)->get_interesting_method_entry(NULL) != NULL) {
686 entry_at(i)->print(tty, i);
687 }
688 }
689 }
690 #endif // INCLUDE_JVMTI
691
692
693 // Printing
694
695 void ConstantPoolCache::print_on(outputStream* st) const {
696 assert(is_constantPoolCache(), "obj must be constant pool cache");
697 st->print_cr("%s", internal_name());
698 // print constant pool cache entries
699 for (int i = 0; i < length(); i++) entry_at(i)->print(st, i);
700 }
701
702 void ConstantPoolCache::print_value_on(outputStream* st) const {
703 assert(is_constantPoolCache(), "obj must be constant pool cache");
704 st->print("cache [%d]", length());
705 print_address_on(st);
|