hotspot/src/share/vm/oops/cpCache.cpp
changeset 15591 b8aa0577f137
parent 14490 5bb45ed999ee
child 15595 54a3423a504f
equal deleted inserted replaced
15469:7719efe7b23d 15591:b8aa0577f137
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   399   objArrayOop resolved_references = cpool->resolved_references();
   399   objArrayOop resolved_references = cpool->resolved_references();
   400   return resolved_references->obj_at(ref_index);
   400   return resolved_references->obj_at(ref_index);
   401 }
   401 }
   402 
   402 
   403 
   403 
       
   404 #if INCLUDE_JVMTI
   404 // RedefineClasses() API support:
   405 // RedefineClasses() API support:
   405 // If this constantPoolCacheEntry refers to old_method then update it
   406 // If this ConstantPoolCacheEntry refers to old_method then update it
   406 // to refer to new_method.
   407 // to refer to new_method.
   407 bool ConstantPoolCacheEntry::adjust_method_entry(Method* old_method,
   408 bool ConstantPoolCacheEntry::adjust_method_entry(Method* old_method,
   408        Method* new_method, bool * trace_name_printed) {
   409        Method* new_method, bool * trace_name_printed) {
   409 
   410 
   410   if (is_vfinal()) {
   411   if (is_vfinal()) {
   458   }
   459   }
   459 
   460 
   460   return false;
   461   return false;
   461 }
   462 }
   462 
   463 
   463 #ifndef PRODUCT
   464 // a constant pool cache entry should never contain old or obsolete methods
   464 bool ConstantPoolCacheEntry::check_no_old_entries() {
   465 bool ConstantPoolCacheEntry::check_no_old_or_obsolete_entries() {
   465   if (is_vfinal()) {
   466   if (is_vfinal()) {
       
   467     // virtual and final so _f2 contains method ptr instead of vtable index
   466     Metadata* f2 = (Metadata*)_f2;
   468     Metadata* f2 = (Metadata*)_f2;
   467     return (f2->is_valid() && f2->is_method() && !((Method*)f2)->is_old());
   469     // Return false if _f2 refers to an old or an obsolete method.
   468   } else {
   470     // _f2 == NULL || !_f2->is_method() are just as unexpected here.
   469     return (_f1 == NULL || (_f1->is_valid() && _f1->is_method() && !((Method*)_f1)->is_old()));
   471     return (f2 != NULL NOT_PRODUCT(&& f2->is_valid()) && f2->is_method() &&
   470   }
   472             !((Method*)f2)->is_old() && !((Method*)f2)->is_obsolete());
   471 }
   473   } else if (_f1 == NULL ||
   472 #endif
   474              (NOT_PRODUCT(_f1->is_valid() &&) !_f1->is_method())) {
       
   475     // _f1 == NULL || !_f1->is_method() are OK here
       
   476     return true;
       
   477   }
       
   478   // return false if _f1 refers to an old or an obsolete method
       
   479   return (NOT_PRODUCT(_f1->is_valid() &&) _f1->is_method() &&
       
   480           !((Method*)_f1)->is_old() && !((Method*)_f1)->is_obsolete());
       
   481 }
   473 
   482 
   474 bool ConstantPoolCacheEntry::is_interesting_method_entry(Klass* k) {
   483 bool ConstantPoolCacheEntry::is_interesting_method_entry(Klass* k) {
   475   if (!is_method_entry()) {
   484   if (!is_method_entry()) {
   476     // not a method entry so not interesting by default
   485     // not a method entry so not interesting by default
   477     return false;
   486     return false;
   500   }
   509   }
   501 
   510 
   502   // the method is in the interesting class so the entry is interesting
   511   // the method is in the interesting class so the entry is interesting
   503   return true;
   512   return true;
   504 }
   513 }
       
   514 #endif // INCLUDE_JVMTI
   505 
   515 
   506 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
   516 void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
   507   // print separator
   517   // print separator
   508   if (index == 0) st->print_cr("                 -------------");
   518   if (index == 0) st->print_cr("                 -------------");
   509   // print entry
   519   // print entry
   510   st->print("%3d  ("PTR_FORMAT")  ", index, (intptr_t)this);
   520   st->print("%3d  ("PTR_FORMAT")  ", index, (intptr_t)this);
   511     st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(), constant_pool_index());
   521   st->print_cr("[%02x|%02x|%5d]", bytecode_2(), bytecode_1(),
       
   522                constant_pool_index());
   512   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f1);
   523   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f1);
   513   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f2);
   524   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_f2);
   514   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_flags);
   525   st->print_cr("                 [   "PTR_FORMAT"]", (intptr_t)_flags);
   515   st->print_cr("                 -------------");
   526   st->print_cr("                 -------------");
   516 }
   527 }
   550       ref += ConstantPoolCacheEntry::_indy_resolved_references_entries - 1;  // skip extra entries
   561       ref += ConstantPoolCacheEntry::_indy_resolved_references_entries - 1;  // skip extra entries
   551     }
   562     }
   552   }
   563   }
   553 }
   564 }
   554 
   565 
       
   566 #if INCLUDE_JVMTI
   555 // RedefineClasses() API support:
   567 // RedefineClasses() API support:
   556 // If any entry of this constantPoolCache points to any of
   568 // If any entry of this ConstantPoolCache points to any of
   557 // old_methods, replace it with the corresponding new_method.
   569 // old_methods, replace it with the corresponding new_method.
   558 void ConstantPoolCache::adjust_method_entries(Method** old_methods, Method** new_methods,
   570 void ConstantPoolCache::adjust_method_entries(Method** old_methods, Method** new_methods,
   559                                                      int methods_length, bool * trace_name_printed) {
   571                                                      int methods_length, bool * trace_name_printed) {
   560 
   572 
   561   if (methods_length == 0) {
   573   if (methods_length == 0) {
   570     if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
   582     if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
   571       // skip uninteresting methods
   583       // skip uninteresting methods
   572       continue;
   584       continue;
   573     }
   585     }
   574 
   586 
   575     // The constantPoolCache contains entries for several different
   587     // The ConstantPoolCache contains entries for several different
   576     // things, but we only care about methods. In fact, we only care
   588     // things, but we only care about methods. In fact, we only care
   577     // about methods in the same class as the one that contains the
   589     // about methods in the same class as the one that contains the
   578     // old_methods. At this point, we have an interesting entry.
   590     // old_methods. At this point, we have an interesting entry.
   579 
   591 
   580     for (int j = 0; j < methods_length; j++) {
   592     for (int j = 0; j < methods_length; j++) {
   589       }
   601       }
   590     }
   602     }
   591   }
   603   }
   592 }
   604 }
   593 
   605 
   594 #ifndef PRODUCT
   606 // the constant pool cache should never contain old or obsolete methods
   595 bool ConstantPoolCache::check_no_old_entries() {
   607 bool ConstantPoolCache::check_no_old_or_obsolete_entries() {
   596   for (int i = 1; i < length(); i++) {
   608   for (int i = 1; i < length(); i++) {
   597     if (entry_at(i)->is_interesting_method_entry(NULL) &&
   609     if (entry_at(i)->is_interesting_method_entry(NULL) &&
   598        !entry_at(i)->check_no_old_entries()) {
   610         !entry_at(i)->check_no_old_or_obsolete_entries()) {
   599       return false;
   611       return false;
   600     }
   612     }
   601   }
   613   }
   602   return true;
   614   return true;
   603 }
   615 }
   604 #endif // PRODUCT
   616 
       
   617 void ConstantPoolCache::dump_cache() {
       
   618   for (int i = 1; i < length(); i++) {
       
   619     if (entry_at(i)->is_interesting_method_entry(NULL)) {
       
   620       entry_at(i)->print(tty, i);
       
   621     }
       
   622   }
       
   623 }
       
   624 #endif // INCLUDE_JVMTI
   605 
   625 
   606 
   626 
   607 // Printing
   627 // Printing
   608 
   628 
   609 void ConstantPoolCache::print_on(outputStream* st) const {
   629 void ConstantPoolCache::print_on(outputStream* st) const {