1 /*
2 * Copyright (c) 1998, 2011, 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 *
453 _f1 = new_method;
454 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
455 if (!(*trace_name_printed)) {
456 // RC_TRACE_MESG macro has an embedded ResourceMark
457 RC_TRACE_MESG(("adjust: name=%s",
458 Klass::cast(old_method->method_holder())->external_name()));
459 *trace_name_printed = true;
460 }
461 // RC_TRACE macro has an embedded ResourceMark
462 RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
463 new_method->name()->as_C_string(),
464 new_method->signature()->as_C_string()));
465 }
466
467 return true;
468 }
469
470 return false;
471 }
472
473 bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
474 if (!is_method_entry()) {
475 // not a method entry so not interesting by default
476 return false;
477 }
478
479 methodOop m = NULL;
480 if (is_vfinal()) {
481 // virtual and final so _f2 contains method ptr instead of vtable index
482 m = (methodOop)_f2;
483 } else if ((oop)_f1 == NULL) {
484 // NULL _f1 means this is a virtual entry so also not interesting
485 return false;
486 } else {
487 if (!((oop)_f1)->is_method()) {
488 // _f1 can also contain a klassOop for an interface
489 return false;
490 }
491 m = (methodOop)_f1;
492 }
493
494 assert(m != NULL && m->is_method(), "sanity check");
495 if (m == NULL || !m->is_method() || m->method_holder() != k) {
496 // robustness for above sanity checks or method is not in
497 // the interesting class
498 return false;
499 }
500
501 // the method is in the interesting class so the entry is interesting
502 return true;
503 }
504
505 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
506 // print separator
507 if (index == 0) tty->print_cr(" -------------");
508 // print entry
509 tty->print("%3d ("PTR_FORMAT") ", index, (intptr_t)this);
510 if (is_secondary_entry())
511 tty->print_cr("[%5d|secondary]", main_entry_index());
512 else
513 tty->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(), constant_pool_index());
514 tty->print_cr(" [ "PTR_FORMAT"]", (intptr_t)(oop)_f1);
515 tty->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_f2);
559 continue;
560 }
561
562 // The constantPoolCache contains entries for several different
563 // things, but we only care about methods. In fact, we only care
564 // about methods in the same class as the one that contains the
565 // old_methods. At this point, we have an interesting entry.
566
567 for (int j = 0; j < methods_length; j++) {
568 methodOop old_method = old_methods[j];
569 methodOop new_method = new_methods[j];
570
571 if (entry_at(i)->adjust_method_entry(old_method, new_method,
572 trace_name_printed)) {
573 // current old_method matched this entry and we updated it so
574 // break out and get to the next interesting entry if there one
575 break;
576 }
577 }
578 }
579 }
|
1 /*
2 * Copyright (c) 1998, 2013, 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 *
453 _f1 = new_method;
454 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
455 if (!(*trace_name_printed)) {
456 // RC_TRACE_MESG macro has an embedded ResourceMark
457 RC_TRACE_MESG(("adjust: name=%s",
458 Klass::cast(old_method->method_holder())->external_name()));
459 *trace_name_printed = true;
460 }
461 // RC_TRACE macro has an embedded ResourceMark
462 RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
463 new_method->name()->as_C_string(),
464 new_method->signature()->as_C_string()));
465 }
466
467 return true;
468 }
469
470 return false;
471 }
472
473 // a constant pool cache entry should never contain old or obsolete methods
474 bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
475 if (is_vfinal()) {
476 // virtual and final so _f2 contains method ptr instead of vtable index
477 methodOop m = (methodOop)_f2;
478 // Return false if _f2 refers to an old or an obsolete method.
479 // _f2 == NULL || !m->is_method() are just as unexpected here.
480 return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
481 } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
482 // _f1 == NULL || !_f1->is_method() are OK here
483 return true;
484 }
485
486 methodOop m = (methodOop)_f1;
487 // return false if _f1 refers to an old or an obsolete method
488 return (!m->is_old() && !m->is_obsolete());
489 }
490
491 bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
492 if (!is_method_entry()) {
493 // not a method entry so not interesting by default
494 return false;
495 }
496
497 methodOop m = NULL;
498 if (is_vfinal()) {
499 // virtual and final so _f2 contains method ptr instead of vtable index
500 m = (methodOop)_f2;
501 } else if ((oop)_f1 == NULL) {
502 // NULL _f1 means this is a virtual entry so also not interesting
503 return false;
504 } else {
505 if (!((oop)_f1)->is_method()) {
506 // _f1 can also contain a klassOop for an interface
507 return false;
508 }
509 m = (methodOop)_f1;
510 }
511
512 assert(m != NULL && m->is_method(), "sanity check");
513 if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
514 // robustness for above sanity checks or method is not in
515 // the interesting class
516 return false;
517 }
518
519 // the method is in the interesting class so the entry is interesting
520 return true;
521 }
522
523 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
524 // print separator
525 if (index == 0) tty->print_cr(" -------------");
526 // print entry
527 tty->print("%3d ("PTR_FORMAT") ", index, (intptr_t)this);
528 if (is_secondary_entry())
529 tty->print_cr("[%5d|secondary]", main_entry_index());
530 else
531 tty->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(), constant_pool_index());
532 tty->print_cr(" [ "PTR_FORMAT"]", (intptr_t)(oop)_f1);
533 tty->print_cr(" [ "PTR_FORMAT"]", (intptr_t)_f2);
577 continue;
578 }
579
580 // The constantPoolCache contains entries for several different
581 // things, but we only care about methods. In fact, we only care
582 // about methods in the same class as the one that contains the
583 // old_methods. At this point, we have an interesting entry.
584
585 for (int j = 0; j < methods_length; j++) {
586 methodOop old_method = old_methods[j];
587 methodOop new_method = new_methods[j];
588
589 if (entry_at(i)->adjust_method_entry(old_method, new_method,
590 trace_name_printed)) {
591 // current old_method matched this entry and we updated it so
592 // break out and get to the next interesting entry if there one
593 break;
594 }
595 }
596 }
597 }
598
599 // the constant pool cache should never contain old or obsolete methods
600 bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
601 for (int i = 1; i < length(); i++) {
602 if (entry_at(i)->is_interesting_method_entry(NULL) &&
603 !entry_at(i)->check_no_old_or_obsolete_entries()) {
604 return false;
605 }
606 }
607 return true;
608 }
609
610 void constantPoolCacheOopDesc::dump_cache() {
611 for (int i = 1; i < length(); i++) {
612 if (entry_at(i)->is_interesting_method_entry(NULL)) {
613 entry_at(i)->print(tty, i);
614 }
615 }
616 }
|