src/share/vm/oops/cpCache.cpp

Print this page




 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   }


 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 
 563 // Implementation of ConstantPoolCache


 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 }




 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   }


 522     // NULL _f1 means this is a virtual entry so also not interesting
 523     return false;
 524   } else {
 525     if (!(_f1->is_method())) {
 526       // _f1 can also contain a Klass* for an interface
 527       return false;
 528     }
 529     m = f1_as_method();
 530   }
 531 
 532   assert(m != NULL && m->is_method(), "sanity check");
 533   if (m == NULL || !m->is_method() || (k != NULL && m->method_holder() != k)) {
 534     // robustness for above sanity checks or method is not in
 535     // the interesting class
 536     return false;
 537   }
 538 
 539   // the method is in the interesting class so the entry is interesting
 540   return true;
 541 }
 542 
 543 Method* ConstantPoolCacheEntry::get_interesting_method_entry(Klass* k) {
 544   if (!is_method_entry()) {
 545     // not a method entry so not interesting by default
 546     return NULL;
 547   }
 548   Method* m = NULL;
 549   if (is_vfinal()) {
 550     // virtual and final so _f2 contains method ptr instead of vtable index
 551     m = f2_as_vfinal_method();
 552   } else if (is_f1_null()) {
 553     // NULL _f1 means this is a virtual entry so also not interesting
 554     return NULL;
 555   } else {
 556     if (!(_f1->is_method())) {
 557       // _f1 can also contain a Klass* for an interface
 558       return NULL;
 559     }
 560     m = f1_as_method();
 561   }
 562   assert(m != NULL && m->is_method(), "sanity check");
 563   if (m == NULL || !m->is_method() || m->method_holder() != k) {
 564     // robustness for above sanity checks or method is not in
 565     // the interesting class
 566     return NULL;
 567   }
 568   // the method is in the interesting class so the entry is interesting
 569   return m;
 570 }
 571 #endif // INCLUDE_JVMTI
 572 
 573 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
 574   // print separator
 575   if (index == 0) st->print_cr("                 -------------");
 576   // print entry
 577   st->print("%3d  ("PTR_FORMAT")  ", index, (intptr_t)this);
 578   st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(),
 579                constant_pool_index());
 580   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f1);
 581   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f2);
 582   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_flags);
 583   st->print_cr("                 -------------");
 584 }
 585 
 586 void ConstantPoolCacheEntry::verify(outputStream* st) const {
 587   // not implemented yet
 588 }
 589 
 590 // Implementation of ConstantPoolCache


 659       continue;
 660     }
 661 
 662     // The ConstantPoolCache contains entries for several different
 663     // things, but we only care about methods. In fact, we only care
 664     // about methods in the same class as the one that contains the
 665     // old_methods. At this point, we have an interesting entry.
 666 
 667     for (int j = 0; j < methods_length; j++) {
 668       Method* old_method = old_methods[j];
 669       Method* new_method = new_methods[j];
 670 
 671       if (entry_at(i)->adjust_method_entry(old_method, new_method,
 672           trace_name_printed)) {
 673         // current old_method matched this entry and we updated it so
 674         // break out and get to the next interesting entry if there one
 675         break;
 676       }
 677     }
 678   }
 679 }
 680 
 681 // If any entry of this ConstantPoolCache points to any of
 682 // old_methods, replace it with the corresponding new_method.
 683 void ConstantPoolCache::adjust_method_entries(InstanceKlass* holder, bool * trace_name_printed) {
 684   for (int i = 0; i < length(); i++) {
 685     ConstantPoolCacheEntry* entry = entry_at(i);
 686     Method* old_method = entry->get_interesting_method_entry(holder);
 687     if (old_method == NULL || !old_method->is_old()) {
 688       continue; // skip uninteresting entries
 689     }
 690     if (old_method->is_deleted()) {
 691       // clean up entries with deleted methods
 692       entry->initialize_entry(entry->constant_pool_index());
 693       continue;
 694     }
 695     Method* new_method = holder->method_with_idnum(old_method->orig_method_idnum());
 696     assert(new_method != NULL, "method_with_idnum() should not be NULL");
 697     if (old_method != new_method) {
 698       entry_at(i)->adjust_method_entry(old_method, new_method, trace_name_printed);
 699     }
 700   }
 701 }
 702 
 703 // the constant pool cache should never contain old or obsolete methods
 704 bool ConstantPoolCache::check_no_old_or_obsolete_entries() {
 705   for (int i = 1; i < length(); i++) {
 706     if (entry_at(i)->is_interesting_method_entry(NULL) &&
 707         !entry_at(i)->check_no_old_or_obsolete_entries()) {
 708       return false;
 709     }
 710   }
 711   return true;
 712 }
 713 
 714 void ConstantPoolCache::dump_cache() {
 715   for (int i = 1; i < length(); i++) {
 716     if (entry_at(i)->is_interesting_method_entry(NULL)) {
 717       entry_at(i)->print(tty, i);
 718     }
 719   }
 720 }