src/share/vm/oops/cpCacheOop.cpp

Print this page


   1 /*
   2  * Copyright (c) 1998, 2012, 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  *


 558     _f1 = new_method;
 559     if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
 560       if (!(*trace_name_printed)) {
 561         // RC_TRACE_MESG macro has an embedded ResourceMark
 562         RC_TRACE_MESG(("adjust: name=%s",
 563           Klass::cast(old_method->method_holder())->external_name()));
 564         *trace_name_printed = true;
 565       }
 566       // RC_TRACE macro has an embedded ResourceMark
 567       RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
 568         new_method->name()->as_C_string(),
 569         new_method->signature()->as_C_string()));
 570     }
 571 
 572     return true;
 573   }
 574 
 575   return false;
 576 }
 577 


















 578 bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
 579   if (!is_method_entry()) {
 580     // not a method entry so not interesting by default
 581     return false;
 582   }
 583 
 584   methodOop m = NULL;
 585   if (is_vfinal()) {
 586     // virtual and final so _f2 contains method ptr instead of vtable index
 587     m = f2_as_vfinal_method();
 588   } else if (is_f1_null()) {
 589     // NULL _f1 means this is a virtual entry so also not interesting
 590     return false;
 591   } else {
 592     oop f1 = _f1;  // _f1 is volatile
 593     if (!f1->is_method()) {
 594       // _f1 can also contain a klassOop for an interface
 595       return false;
 596     }
 597     m = f1_as_method();
 598   }
 599 
 600   assert(m != NULL && m->is_method(), "sanity check");
 601   if (m == NULL || !m->is_method() || m->method_holder() != k) {
 602     // robustness for above sanity checks or method is not in
 603     // the interesting class
 604     return false;
 605   }
 606 
 607   // the method is in the interesting class so the entry is interesting
 608   return true;
 609 }
 610 
 611 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
 612   // print separator
 613   if (index == 0) st->print_cr("                 -------------");
 614   // print entry
 615   st->print("%3d  ("PTR_FORMAT")  ", index, (intptr_t)this);
 616   if (is_secondary_entry())
 617     st->print_cr("[%5d|secondary]", main_entry_index());
 618   else
 619     st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(), constant_pool_index());
 620   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)(oop)_f1);
 621   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f2);


 665       continue;
 666     }
 667 
 668     // The constantPoolCache contains entries for several different
 669     // things, but we only care about methods. In fact, we only care
 670     // about methods in the same class as the one that contains the
 671     // old_methods. At this point, we have an interesting entry.
 672 
 673     for (int j = 0; j < methods_length; j++) {
 674       methodOop old_method = old_methods[j];
 675       methodOop new_method = new_methods[j];
 676 
 677       if (entry_at(i)->adjust_method_entry(old_method, new_method,
 678           trace_name_printed)) {
 679         // current old_method matched this entry and we updated it so
 680         // break out and get to the next interesting entry if there one
 681         break;
 682       }
 683     }
 684   }



















 685 }
   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  *


 558     _f1 = new_method;
 559     if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
 560       if (!(*trace_name_printed)) {
 561         // RC_TRACE_MESG macro has an embedded ResourceMark
 562         RC_TRACE_MESG(("adjust: name=%s",
 563           Klass::cast(old_method->method_holder())->external_name()));
 564         *trace_name_printed = true;
 565       }
 566       // RC_TRACE macro has an embedded ResourceMark
 567       RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
 568         new_method->name()->as_C_string(),
 569         new_method->signature()->as_C_string()));
 570     }
 571 
 572     return true;
 573   }
 574 
 575   return false;
 576 }
 577 
 578 // a constant pool cache entry should never contain old or obsolete methods
 579 bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
 580   if (is_vfinal()) {
 581     // virtual and final so _f2 contains method ptr instead of vtable index
 582     methodOop m = (methodOop)_f2;
 583     // Return false if _f2 refers to an old or an obsolete method.
 584     // _f2 == NULL || !m->is_method() are just as unexpected here.
 585     return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
 586   } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
 587     // _f1 == NULL || !_f1->is_method() are OK here
 588     return true;
 589   }
 590 
 591   methodOop m = (methodOop)_f1;
 592   // return false if _f1 refers to an old or an obsolete method
 593   return (!m->is_old() && !m->is_obsolete());
 594 }
 595 
 596 bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
 597   if (!is_method_entry()) {
 598     // not a method entry so not interesting by default
 599     return false;
 600   }
 601 
 602   methodOop m = NULL;
 603   if (is_vfinal()) {
 604     // virtual and final so _f2 contains method ptr instead of vtable index
 605     m = f2_as_vfinal_method();
 606   } else if (is_f1_null()) {
 607     // NULL _f1 means this is a virtual entry so also not interesting
 608     return false;
 609   } else {
 610     oop f1 = _f1;  // _f1 is volatile
 611     if (!f1->is_method()) {
 612       // _f1 can also contain a klassOop for an interface
 613       return false;
 614     }
 615     m = f1_as_method();
 616   }
 617 
 618   assert(m != NULL && m->is_method(), "sanity check");
 619   if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
 620     // robustness for above sanity checks or method is not in
 621     // the interesting class
 622     return false;
 623   }
 624 
 625   // the method is in the interesting class so the entry is interesting
 626   return true;
 627 }
 628 
 629 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
 630   // print separator
 631   if (index == 0) st->print_cr("                 -------------");
 632   // print entry
 633   st->print("%3d  ("PTR_FORMAT")  ", index, (intptr_t)this);
 634   if (is_secondary_entry())
 635     st->print_cr("[%5d|secondary]", main_entry_index());
 636   else
 637     st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(), constant_pool_index());
 638   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)(oop)_f1);
 639   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f2);


 683       continue;
 684     }
 685 
 686     // The constantPoolCache contains entries for several different
 687     // things, but we only care about methods. In fact, we only care
 688     // about methods in the same class as the one that contains the
 689     // old_methods. At this point, we have an interesting entry.
 690 
 691     for (int j = 0; j < methods_length; j++) {
 692       methodOop old_method = old_methods[j];
 693       methodOop new_method = new_methods[j];
 694 
 695       if (entry_at(i)->adjust_method_entry(old_method, new_method,
 696           trace_name_printed)) {
 697         // current old_method matched this entry and we updated it so
 698         // break out and get to the next interesting entry if there one
 699         break;
 700       }
 701     }
 702   }
 703 }
 704 
 705 // the constant pool cache should never contain old or obsolete methods
 706 bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
 707   for (int i = 1; i < length(); i++) {
 708     if (entry_at(i)->is_interesting_method_entry(NULL) &&
 709         !entry_at(i)->check_no_old_or_obsolete_entries()) {
 710       return false;
 711     }
 712   }
 713   return true;
 714 }
 715 
 716 void constantPoolCacheOopDesc::dump_cache() {
 717   for (int i = 1; i < length(); i++) {
 718     if (entry_at(i)->is_interesting_method_entry(NULL)) {
 719       entry_at(i)->print(tty, i);
 720     }
 721   }
 722 }