< prev index next >

src/share/vm/classfile/loaderConstraints.cpp

Print this page




   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  *
  23  */
  24 
  25 #include "precompiled.hpp"

  26 #include "classfile/classLoaderData.inline.hpp"
  27 #include "classfile/loaderConstraints.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/handles.inline.hpp"
  31 #include "runtime/safepoint.hpp"
  32 #include "utilities/hashtable.inline.hpp"
  33 
  34 void LoaderConstraintEntry::set_loader(int i, oop p) {
  35   set_loader_data(i, ClassLoaderData::class_loader_data(p));
  36 }
  37 
  38 LoaderConstraintTable::LoaderConstraintTable(int nof_buckets)
  39   : Hashtable<InstanceKlass*, mtClass>(nof_buckets, sizeof(LoaderConstraintEntry)) {};
  40 
  41 
  42 LoaderConstraintEntry* LoaderConstraintTable::new_entry(
  43                                  unsigned int hash, Symbol* name,
  44                                  InstanceKlass* klass, int num_loaders,
  45                                  int max_loaders) {
  46   LoaderConstraintEntry* entry;
  47   entry = (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::new_entry(hash, klass);
  48   entry->set_name(name);
  49   entry->set_num_loaders(num_loaders);
  50   entry->set_max_loaders(max_loaders);
  51   return entry;
  52 }
  53 
  54 void LoaderConstraintTable::free_entry(LoaderConstraintEntry *entry) {
  55   // decrement name refcount before freeing
  56   entry->name()->decrement_refcount();
  57   Hashtable<InstanceKlass*, mtClass>::free_entry(entry);
  58 }
  59 


 412   // p1->klass() are all NULL.  In addition, all three must have
 413   // matching non-NULL values, otherwise either the constraints would
 414   // have been violated, or the constraints had been corrupted (and an
 415   // assertion would fail).
 416   if (p2->klass() != NULL) {
 417     assert(p2->klass() == klass, "constraints corrupted");
 418   }
 419   if (p1->klass() == NULL) {
 420     p1->set_klass(klass);
 421   } else {
 422     assert(p1->klass() == klass, "constraints corrupted");
 423   }
 424 
 425   *pp2 = p2->next();
 426   FREE_C_HEAP_ARRAY(oop, p2->loaders());
 427   free_entry(p2);
 428   return;
 429 }
 430 
 431 
 432 void LoaderConstraintTable::verify(Dictionary* dictionary,
 433                                    PlaceholderTable* placeholders) {
 434   Thread *thread = Thread::current();
 435   for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {
 436     for (LoaderConstraintEntry* probe = bucket(cindex);
 437                                 probe != NULL;
 438                                 probe = probe->next()) {
 439       if (probe->klass() != NULL) {
 440         InstanceKlass* ik = probe->klass();
 441         guarantee(ik->name() == probe->name(), "name should match");
 442         Symbol* name = ik->name();
 443         ClassLoaderData* loader_data = ik->class_loader_data();
 444         unsigned int d_hash = dictionary->compute_hash(name, loader_data);

 445         int d_index = dictionary->hash_to_index(d_hash);
 446         InstanceKlass* k = dictionary->find_class(d_index, d_hash, name, loader_data);
 447         if (k != NULL) {
 448           // We found the class in the system dictionary, so we should
 449           // make sure that the Klass* matches what we already have.
 450           guarantee(k == probe->klass(), "klass should be in dictionary");
 451         } else {
 452           // If we don't find the class in the system dictionary, it
 453           // has to be in the placeholders table.
 454           unsigned int p_hash = placeholders->compute_hash(name, loader_data);
 455           int p_index = placeholders->hash_to_index(p_hash);
 456           PlaceholderEntry* entry = placeholders->get_entry(p_index, p_hash,
 457                                                             name, loader_data);
 458 
 459           // The InstanceKlass might not be on the entry, so the only
 460           // thing we can check here is whether we were successful in
 461           // finding the class in the placeholders table.
 462           guarantee(entry != NULL, "klass should be in the placeholders");
 463         }
 464       }
 465       for (int n = 0; n< probe->num_loaders(); n++) {
 466         assert(ClassLoaderDataGraph::contains_loader_data(probe->loader_data(n)), "The loader is missing");
 467       }
 468     }
 469   }
 470 }
 471 
 472 #ifndef PRODUCT
 473 
 474 // Called with the system dictionary lock held
 475 void LoaderConstraintTable::print() {
 476   ResourceMark rm;
 477   assert_locked_or_safepoint(SystemDictionary_lock);
 478   tty->print_cr("Java loader constraints (entries=%d)", _loader_constraint_size);
 479   for (int cindex = 0; cindex < _loader_constraint_size; cindex++) {

 480     for (LoaderConstraintEntry* probe = bucket(cindex);
 481                                 probe != NULL;
 482                                 probe = probe->next()) {
 483       tty->print("%4d: ", cindex);
 484       probe->name()->print();
 485       tty->print(" , loaders:");
 486       for (int n = 0; n < probe->num_loaders(); n++) {
 487         probe->loader_data(n)->print_value();
 488         tty->print(", ");
 489       }
 490       tty->cr();
 491     }
 492   }
 493 }
 494 #endif


   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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/dictionary.hpp"
  27 #include "classfile/classLoaderData.inline.hpp"
  28 #include "classfile/loaderConstraints.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "oops/oop.inline.hpp"
  31 #include "runtime/handles.inline.hpp"
  32 #include "runtime/safepoint.hpp"
  33 #include "utilities/hashtable.inline.hpp"
  34 
  35 void LoaderConstraintEntry::set_loader(int i, oop p) {
  36   set_loader_data(i, ClassLoaderData::class_loader_data(p));
  37 }
  38 
  39 LoaderConstraintTable::LoaderConstraintTable(int table_size)
  40   : Hashtable<InstanceKlass*, mtClass>(table_size, sizeof(LoaderConstraintEntry)) {};
  41 
  42 
  43 LoaderConstraintEntry* LoaderConstraintTable::new_entry(
  44                                  unsigned int hash, Symbol* name,
  45                                  InstanceKlass* klass, int num_loaders,
  46                                  int max_loaders) {
  47   LoaderConstraintEntry* entry;
  48   entry = (LoaderConstraintEntry*)Hashtable<InstanceKlass*, mtClass>::new_entry(hash, klass);
  49   entry->set_name(name);
  50   entry->set_num_loaders(num_loaders);
  51   entry->set_max_loaders(max_loaders);
  52   return entry;
  53 }
  54 
  55 void LoaderConstraintTable::free_entry(LoaderConstraintEntry *entry) {
  56   // decrement name refcount before freeing
  57   entry->name()->decrement_refcount();
  58   Hashtable<InstanceKlass*, mtClass>::free_entry(entry);
  59 }
  60 


 413   // p1->klass() are all NULL.  In addition, all three must have
 414   // matching non-NULL values, otherwise either the constraints would
 415   // have been violated, or the constraints had been corrupted (and an
 416   // assertion would fail).
 417   if (p2->klass() != NULL) {
 418     assert(p2->klass() == klass, "constraints corrupted");
 419   }
 420   if (p1->klass() == NULL) {
 421     p1->set_klass(klass);
 422   } else {
 423     assert(p1->klass() == klass, "constraints corrupted");
 424   }
 425 
 426   *pp2 = p2->next();
 427   FREE_C_HEAP_ARRAY(oop, p2->loaders());
 428   free_entry(p2);
 429   return;
 430 }
 431 
 432 
 433 void LoaderConstraintTable::verify(PlaceholderTable* placeholders) {

 434   Thread *thread = Thread::current();
 435   for (int cindex = 0; cindex < table_size(); cindex++) {
 436     for (LoaderConstraintEntry* probe = bucket(cindex);
 437                                 probe != NULL;
 438                                 probe = probe->next()) {
 439       if (probe->klass() != NULL) {
 440         InstanceKlass* ik = probe->klass();
 441         guarantee(ik->name() == probe->name(), "name should match");
 442         Symbol* name = ik->name();
 443         ClassLoaderData* loader_data = ik->class_loader_data();
 444         Dictionary* dictionary = loader_data->dictionary();
 445         unsigned int d_hash = dictionary->compute_hash(name);
 446         int d_index = dictionary->hash_to_index(d_hash);
 447         InstanceKlass* k = dictionary->find_class(d_index, d_hash, name);
 448         if (k != NULL) {
 449           // We found the class in the dictionary, so we should
 450           // make sure that the Klass* matches what we already have.
 451           guarantee(k == probe->klass(), "klass should be in dictionary");
 452         } else {
 453           // If we don't find the class in the dictionary, it
 454           // has to be in the placeholders table.
 455           unsigned int p_hash = placeholders->compute_hash(name);
 456           int p_index = placeholders->hash_to_index(p_hash);
 457           PlaceholderEntry* entry = placeholders->get_entry(p_index, p_hash,
 458                                                             name, loader_data);
 459 
 460           // The InstanceKlass might not be on the entry, so the only
 461           // thing we can check here is whether we were successful in
 462           // finding the class in the placeholders table.
 463           guarantee(entry != NULL, "klass should be in the placeholders");
 464         }
 465       }
 466       for (int n = 0; n< probe->num_loaders(); n++) {
 467         assert(ClassLoaderDataGraph::contains_loader_data(probe->loader_data(n)), "The loader is missing");
 468       }
 469     }
 470   }
 471 }
 472 
 473 #ifndef PRODUCT
 474 
 475 // Called with the system dictionary lock held
 476 void LoaderConstraintTable::print() {
 477   ResourceMark rm;
 478   assert_locked_or_safepoint(SystemDictionary_lock);
 479   tty->print_cr("Java loader constraints (entries=%d, constraints=%d)",
 480                 table_size(), number_of_entries());
 481   for (int cindex = 0; cindex < table_size(); cindex++) {
 482     for (LoaderConstraintEntry* probe = bucket(cindex);
 483                                 probe != NULL;
 484                                 probe = probe->next()) {
 485       tty->print("%4d: ", cindex);
 486       probe->name()->print();
 487       tty->print(" , loaders:");
 488       for (int n = 0; n < probe->num_loaders(); n++) {
 489         probe->loader_data(n)->print_value();
 490         tty->print(", ");
 491       }
 492       tty->cr();
 493     }
 494   }
 495 }
 496 #endif
< prev index next >