src/share/vm/oops/cpCacheOop.cpp

Print this page


   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);

 516   tty->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_flags);

 517   tty->print_cr("                 -------------");
 518 }
 519 
 520 void ConstantPoolCacheEntry::verify(outputStream* st) const {
 521   // not implemented yet
 522 }
 523 
 524 // Implementation of ConstantPoolCache
 525 
 526 void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
 527   assert(inverse_index_map.length() == length(), "inverse index map must have same length as cache");
 528   for (int i = 0; i < length(); i++) {
 529     ConstantPoolCacheEntry* e = entry_at(i);
 530     int original_index = inverse_index_map[i];
 531     if ((original_index & Rewriter::_secondary_entry_tag) != 0) {
 532       int main_index = (original_index - Rewriter::_secondary_entry_tag);
 533       assert(!entry_at(main_index)->is_secondary_entry(), "valid main index");
 534       e->initialize_secondary_entry(main_index);
 535     } else {
 536       e->initialize_entry(original_index);


 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     methodOop m = (methodOop)_f2;
 477     // Return false if _f2 refers to an old or an obsolete method.
 478     // _f2 == NULL || !m->is_method() are just as unexpected here.
 479     return (m != NULL && m->is_method() && !m->is_old() && !m->is_obsolete());
 480   } else if ((oop)_f1 == NULL || !((oop)_f1)->is_method()) {
 481     // _f1 == NULL || !_f1->is_method() are OK here
 482     return true;
 483   }
 484 
 485   methodOop m = (methodOop)_f1;
 486   // return false if _f1 refers to an old or an obsolete method
 487   return (!m->is_old() && !m->is_obsolete());
 488 }
 489 
 490 bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
 491   if (!is_method_entry()) {
 492     // not a method entry so not interesting by default
 493     return false;
 494   }
 495 
 496   methodOop m = NULL;
 497   if (is_vfinal()) {
 498     // virtual and final so _f2 contains method ptr instead of vtable index
 499     m = (methodOop)_f2;
 500   } else if ((oop)_f1 == NULL) {
 501     // NULL _f1 means this is a virtual entry so also not interesting
 502     return false;
 503   } else {
 504     if (!((oop)_f1)->is_method()) {
 505       // _f1 can also contain a klassOop for an interface
 506       return false;
 507     }
 508     m = (methodOop)_f1;
 509   }
 510 
 511   assert(m != NULL && m->is_method(), "sanity check");
 512   if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
 513     // robustness for above sanity checks or method is not in
 514     // the interesting class
 515     return false;
 516   }
 517 
 518   // the method is in the interesting class so the entry is interesting
 519   return true;
 520 }
 521 
 522 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
 523   // print separator
 524   if (index == 0) {
 525     // adds a searchable prefix when RedefineClasses() tracing is enabled
 526     RC_TRACE_NO_CR(0x00004000, (""));
 527     tty->print_cr("                 -------------");
 528   }
 529   // print entry
 530   RC_TRACE_NO_CR(0x00004000, (""));
 531   tty->print("%3d  ("PTR_FORMAT")  ", index, (intptr_t)this);
 532   if (is_secondary_entry())
 533     tty->print_cr("[%5d|secondary]", main_entry_index());
 534   else
 535     tty->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(), constant_pool_index());
 536   RC_TRACE_NO_CR(0x00004000, (""));
 537   tty->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)(oop)_f1);
 538   RC_TRACE_NO_CR(0x00004000, (""));
 539   tty->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f2);
 540   RC_TRACE_NO_CR(0x00004000, (""));
 541   tty->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_flags);
 542   RC_TRACE_NO_CR(0x00004000, (""));
 543   tty->print_cr("                 -------------");
 544 }
 545 
 546 void ConstantPoolCacheEntry::verify(outputStream* st) const {
 547   // not implemented yet
 548 }
 549 
 550 // Implementation of ConstantPoolCache
 551 
 552 void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
 553   assert(inverse_index_map.length() == length(), "inverse index map must have same length as cache");
 554   for (int i = 0; i < length(); i++) {
 555     ConstantPoolCacheEntry* e = entry_at(i);
 556     int original_index = inverse_index_map[i];
 557     if ((original_index & Rewriter::_secondary_entry_tag) != 0) {
 558       int main_index = (original_index - Rewriter::_secondary_entry_tag);
 559       assert(!entry_at(main_index)->is_secondary_entry(), "valid main index");
 560       e->initialize_secondary_entry(main_index);
 561     } else {
 562       e->initialize_entry(original_index);


 585       continue;
 586     }
 587 
 588     // The constantPoolCache contains entries for several different
 589     // things, but we only care about methods. In fact, we only care
 590     // about methods in the same class as the one that contains the
 591     // old_methods. At this point, we have an interesting entry.
 592 
 593     for (int j = 0; j < methods_length; j++) {
 594       methodOop old_method = old_methods[j];
 595       methodOop new_method = new_methods[j];
 596 
 597       if (entry_at(i)->adjust_method_entry(old_method, new_method,
 598           trace_name_printed)) {
 599         // current old_method matched this entry and we updated it so
 600         // break out and get to the next interesting entry if there one
 601         break;
 602       }
 603     }
 604   }
 605 }
 606 
 607 // the constant pool cache should never contain old or obsolete methods
 608 bool constantPoolCacheOopDesc::check_no_old_or_obsolete_entries() {
 609   for (int i = 1; i < length(); i++) {
 610     if (entry_at(i)->is_interesting_method_entry(NULL) &&
 611         !entry_at(i)->check_no_old_or_obsolete_entries()) {
 612       return false;
 613     }
 614   }
 615   return true;
 616 }
 617 
 618 void constantPoolCacheOopDesc::dump_cache() {
 619   for (int i = 1; i < length(); i++) {
 620     if (entry_at(i)->is_interesting_method_entry(NULL)) {
 621       // adds a searchable prefix when RedefineClasses() tracing is enabled
 622       RC_TRACE_NO_CR(0x00004000, (""));
 623       entry_at(i)->print(tty, i);
 624     }
 625   }
 626 }