8003420: NPG: make new GC root for pd_set

Wed, 09 Oct 2013 10:57:01 +0200

author
tschatzl
date
Wed, 09 Oct 2013 10:57:01 +0200
changeset 5862
82af7d7a0128
parent 5861
b4d8a3d4db73
child 5863
85c1ca43713f

8003420: NPG: make new GC root for pd_set
Summary: Move protection domain oops from system dictionary entries into a seperate set; the system dictionary references entries in that set now. This allows fast iteration during non-classunloading garbage collection. Implementation based on initial prototype from Ioi Lam (iklam).
Reviewed-by: coleenp, iklam

agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainCacheEntry.java file | annotate | diff | comparison | revisions
agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java file | annotate | diff | comparison | revisions
src/share/vm/classfile/dictionary.cpp file | annotate | diff | comparison | revisions
src/share/vm/classfile/dictionary.hpp file | annotate | diff | comparison | revisions
src/share/vm/classfile/systemDictionary.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/vmStructs.cpp file | annotate | diff | comparison | revisions
src/share/vm/utilities/globalDefinitions.hpp file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainCacheEntry.java	Wed Oct 09 10:57:01 2013 +0200
     1.3 @@ -0,0 +1,56 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +package sun.jvm.hotspot.memory;
    1.29 +
    1.30 +import java.util.*;
    1.31 +import sun.jvm.hotspot.debugger.*;
    1.32 +import sun.jvm.hotspot.oops.*;
    1.33 +import sun.jvm.hotspot.runtime.*;
    1.34 +import sun.jvm.hotspot.types.*;
    1.35 +
    1.36 +public class ProtectionDomainCacheEntry extends VMObject {
    1.37 +  private static sun.jvm.hotspot.types.OopField protectionDomainField;
    1.38 +
    1.39 +  static {
    1.40 +    VM.registerVMInitializedObserver(new Observer() {
    1.41 +        public void update(Observable o, Object data) {
    1.42 +          initialize(VM.getVM().getTypeDataBase());
    1.43 +        }
    1.44 +      });
    1.45 +  }
    1.46 +
    1.47 +  private static synchronized void initialize(TypeDataBase db) {
    1.48 +    Type type = db.lookupType("ProtectionDomainCacheEntry");
    1.49 +    protectionDomainField = type.getOopField("_literal");
    1.50 +  }
    1.51 +
    1.52 +  public ProtectionDomainCacheEntry(Address addr) {
    1.53 +    super(addr);
    1.54 +  }
    1.55 +
    1.56 +  public Oop protectionDomain() {
    1.57 +    return VM.getVM().getObjectHeap().newOop(protectionDomainField.getValue(addr));
    1.58 +  }
    1.59 +}
     2.1 --- a/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java	Wed Oct 09 11:18:53 2013 -0700
     2.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java	Wed Oct 09 10:57:01 2013 +0200
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -32,7 +32,7 @@
    2.11  
    2.12  public class ProtectionDomainEntry extends VMObject {
    2.13    private static AddressField nextField;
    2.14 -  private static sun.jvm.hotspot.types.OopField protectionDomainField;
    2.15 +  private static AddressField pdCacheField;
    2.16  
    2.17    static {
    2.18      VM.registerVMInitializedObserver(new Observer() {
    2.19 @@ -46,7 +46,7 @@
    2.20      Type type = db.lookupType("ProtectionDomainEntry");
    2.21  
    2.22      nextField = type.getAddressField("_next");
    2.23 -    protectionDomainField = type.getOopField("_protection_domain");
    2.24 +    pdCacheField = type.getAddressField("_pd_cache");
    2.25    }
    2.26  
    2.27    public ProtectionDomainEntry(Address addr) {
    2.28 @@ -54,10 +54,12 @@
    2.29    }
    2.30  
    2.31    public ProtectionDomainEntry next() {
    2.32 -    return (ProtectionDomainEntry) VMObjectFactory.newObject(ProtectionDomainEntry.class, addr);
    2.33 +    return (ProtectionDomainEntry) VMObjectFactory.newObject(ProtectionDomainEntry.class, nextField.getValue(addr));
    2.34    }
    2.35  
    2.36    public Oop protectionDomain() {
    2.37 -    return VM.getVM().getObjectHeap().newOop(protectionDomainField.getValue(addr));
    2.38 +    ProtectionDomainCacheEntry pd_cache = (ProtectionDomainCacheEntry)
    2.39 +      VMObjectFactory.newObject(ProtectionDomainCacheEntry.class, pdCacheField.getValue(addr));
    2.40 +    return pd_cache.protectionDomain();
    2.41    }
    2.42  }
     3.1 --- a/src/share/vm/classfile/dictionary.cpp	Wed Oct 09 11:18:53 2013 -0700
     3.2 +++ b/src/share/vm/classfile/dictionary.cpp	Wed Oct 09 10:57:01 2013 +0200
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -25,6 +25,7 @@
    3.11  #include "precompiled.hpp"
    3.12  #include "classfile/dictionary.hpp"
    3.13  #include "classfile/systemDictionary.hpp"
    3.14 +#include "memory/iterator.hpp"
    3.15  #include "oops/oop.inline.hpp"
    3.16  #include "prims/jvmtiRedefineClassesTrace.hpp"
    3.17  #include "utilities/hashtable.inline.hpp"
    3.18 @@ -38,17 +39,21 @@
    3.19    : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry)) {
    3.20    _current_class_index = 0;
    3.21    _current_class_entry = NULL;
    3.22 +  _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
    3.23  };
    3.24  
    3.25  
    3.26 -
    3.27  Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t,
    3.28                         int number_of_entries)
    3.29    : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry), t, number_of_entries) {
    3.30    _current_class_index = 0;
    3.31    _current_class_entry = NULL;
    3.32 +  _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
    3.33  };
    3.34  
    3.35 +ProtectionDomainCacheEntry* Dictionary::cache_get(oop protection_domain) {
    3.36 +  return _pd_cache_table->get(protection_domain);
    3.37 +}
    3.38  
    3.39  DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass,
    3.40                                         ClassLoaderData* loader_data) {
    3.41 @@ -105,11 +110,12 @@
    3.42  }
    3.43  
    3.44  
    3.45 -void DictionaryEntry::add_protection_domain(oop protection_domain) {
    3.46 +void DictionaryEntry::add_protection_domain(Dictionary* dict, oop protection_domain) {
    3.47    assert_locked_or_safepoint(SystemDictionary_lock);
    3.48    if (!contains_protection_domain(protection_domain)) {
    3.49 +    ProtectionDomainCacheEntry* entry = dict->cache_get(protection_domain);
    3.50      ProtectionDomainEntry* new_head =
    3.51 -                new ProtectionDomainEntry(protection_domain, _pd_set);
    3.52 +                new ProtectionDomainEntry(entry, _pd_set);
    3.53      // Warning: Preserve store ordering.  The SystemDictionary is read
    3.54      //          without locks.  The new ProtectionDomainEntry must be
    3.55      //          complete before other threads can be allowed to see it
    3.56 @@ -193,7 +199,10 @@
    3.57  
    3.58  
    3.59  void Dictionary::always_strong_oops_do(OopClosure* blk) {
    3.60 -  // Follow all system classes and temporary placeholders in dictionary
    3.61 +  // Follow all system classes and temporary placeholders in dictionary; only
    3.62 +  // protection domain oops contain references into the heap. In a first
    3.63 +  // pass over the system dictionary determine which need to be treated as
    3.64 +  // strongly reachable and mark them as such.
    3.65    for (int index = 0; index < table_size(); index++) {
    3.66      for (DictionaryEntry *probe = bucket(index);
    3.67                            probe != NULL;
    3.68 @@ -201,10 +210,13 @@
    3.69        Klass* e = probe->klass();
    3.70        ClassLoaderData* loader_data = probe->loader_data();
    3.71        if (is_strongly_reachable(loader_data, e)) {
    3.72 -        probe->protection_domain_set_oops_do(blk);
    3.73 +        probe->set_strongly_reachable();
    3.74        }
    3.75      }
    3.76    }
    3.77 +  // Then iterate over the protection domain cache to apply the closure on the
    3.78 +  // previously marked ones.
    3.79 +  _pd_cache_table->always_strong_oops_do(blk);
    3.80  }
    3.81  
    3.82  
    3.83 @@ -266,18 +278,12 @@
    3.84    }
    3.85  }
    3.86  
    3.87 -
    3.88  void Dictionary::oops_do(OopClosure* f) {
    3.89 -  for (int index = 0; index < table_size(); index++) {
    3.90 -    for (DictionaryEntry* probe = bucket(index);
    3.91 -                          probe != NULL;
    3.92 -                          probe = probe->next()) {
    3.93 -      probe->protection_domain_set_oops_do(f);
    3.94 -    }
    3.95 -  }
    3.96 +  // Only the protection domain oops contain references into the heap. Iterate
    3.97 +  // over all of them.
    3.98 +  _pd_cache_table->oops_do(f);
    3.99  }
   3.100  
   3.101 -
   3.102  void Dictionary::methods_do(void f(Method*)) {
   3.103    for (int index = 0; index < table_size(); index++) {
   3.104      for (DictionaryEntry* probe = bucket(index);
   3.105 @@ -292,6 +298,11 @@
   3.106    }
   3.107  }
   3.108  
   3.109 +void Dictionary::unlink(BoolObjectClosure* is_alive) {
   3.110 +  // Only the protection domain cache table may contain references to the heap
   3.111 +  // that need to be unlinked.
   3.112 +  _pd_cache_table->unlink(is_alive);
   3.113 +}
   3.114  
   3.115  Klass* Dictionary::try_get_next_class() {
   3.116    while (true) {
   3.117 @@ -306,7 +317,6 @@
   3.118    // never reached
   3.119  }
   3.120  
   3.121 -
   3.122  // Add a loaded class to the system dictionary.
   3.123  // Readers of the SystemDictionary aren't always locked, so _buckets
   3.124  // is volatile. The store of the next field in the constructor is
   3.125 @@ -396,7 +406,7 @@
   3.126    assert(protection_domain() != NULL,
   3.127           "real protection domain should be present");
   3.128  
   3.129 -  entry->add_protection_domain(protection_domain());
   3.130 +  entry->add_protection_domain(this, protection_domain());
   3.131  
   3.132    assert(entry->contains_protection_domain(protection_domain()),
   3.133           "now protection domain should be present");
   3.134 @@ -446,6 +456,146 @@
   3.135    }
   3.136  }
   3.137  
   3.138 +ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size)
   3.139 +  : Hashtable<oop, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
   3.140 +{
   3.141 +}
   3.142 +
   3.143 +void ProtectionDomainCacheTable::unlink(BoolObjectClosure* is_alive) {
   3.144 +  assert(SafepointSynchronize::is_at_safepoint(), "must be");
   3.145 +  for (int i = 0; i < table_size(); ++i) {
   3.146 +    ProtectionDomainCacheEntry** p = bucket_addr(i);
   3.147 +    ProtectionDomainCacheEntry* entry = bucket(i);
   3.148 +    while (entry != NULL) {
   3.149 +      if (is_alive->do_object_b(entry->literal())) {
   3.150 +        p = entry->next_addr();
   3.151 +      } else {
   3.152 +        *p = entry->next();
   3.153 +        free_entry(entry);
   3.154 +      }
   3.155 +      entry = *p;
   3.156 +    }
   3.157 +  }
   3.158 +}
   3.159 +
   3.160 +void ProtectionDomainCacheTable::oops_do(OopClosure* f) {
   3.161 +  for (int index = 0; index < table_size(); index++) {
   3.162 +    for (ProtectionDomainCacheEntry* probe = bucket(index);
   3.163 +                                     probe != NULL;
   3.164 +                                     probe = probe->next()) {
   3.165 +      probe->oops_do(f);
   3.166 +    }
   3.167 +  }
   3.168 +}
   3.169 +
   3.170 +uint ProtectionDomainCacheTable::bucket_size() {
   3.171 +  return sizeof(ProtectionDomainCacheEntry);
   3.172 +}
   3.173 +
   3.174 +#ifndef PRODUCT
   3.175 +void ProtectionDomainCacheTable::print() {
   3.176 +  tty->print_cr("Protection domain cache table (table_size=%d, classes=%d)",
   3.177 +                table_size(), number_of_entries());
   3.178 +  for (int index = 0; index < table_size(); index++) {
   3.179 +    for (ProtectionDomainCacheEntry* probe = bucket(index);
   3.180 +                                     probe != NULL;
   3.181 +                                     probe = probe->next()) {
   3.182 +      probe->print();
   3.183 +    }
   3.184 +  }
   3.185 +}
   3.186 +
   3.187 +void ProtectionDomainCacheEntry::print() {
   3.188 +  tty->print_cr("entry "PTR_FORMAT" value "PTR_FORMAT" strongly_reachable %d next "PTR_FORMAT,
   3.189 +                this, literal(), _strongly_reachable, next());
   3.190 +}
   3.191 +#endif
   3.192 +
   3.193 +void ProtectionDomainCacheTable::verify() {
   3.194 +  int element_count = 0;
   3.195 +  for (int index = 0; index < table_size(); index++) {
   3.196 +    for (ProtectionDomainCacheEntry* probe = bucket(index);
   3.197 +                                     probe != NULL;
   3.198 +                                     probe = probe->next()) {
   3.199 +      probe->verify();
   3.200 +      element_count++;
   3.201 +    }
   3.202 +  }
   3.203 +  guarantee(number_of_entries() == element_count,
   3.204 +            "Verify of protection domain cache table failed");
   3.205 +  debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
   3.206 +}
   3.207 +
   3.208 +void ProtectionDomainCacheEntry::verify() {
   3.209 +  guarantee(literal()->is_oop(), "must be an oop");
   3.210 +}
   3.211 +
   3.212 +void ProtectionDomainCacheTable::always_strong_oops_do(OopClosure* f) {
   3.213 +  // the caller marked the protection domain cache entries that we need to apply
   3.214 +  // the closure on. Only process them.
   3.215 +  for (int index = 0; index < table_size(); index++) {
   3.216 +    for (ProtectionDomainCacheEntry* probe = bucket(index);
   3.217 +                                     probe != NULL;
   3.218 +                                     probe = probe->next()) {
   3.219 +      if (probe->is_strongly_reachable()) {
   3.220 +        probe->reset_strongly_reachable();
   3.221 +        probe->oops_do(f);
   3.222 +      }
   3.223 +    }
   3.224 +  }
   3.225 +}
   3.226 +
   3.227 +ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(oop protection_domain) {
   3.228 +  unsigned int hash = compute_hash(protection_domain);
   3.229 +  int index = hash_to_index(hash);
   3.230 +
   3.231 +  ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain);
   3.232 +  if (entry == NULL) {
   3.233 +    entry = add_entry(index, hash, protection_domain);
   3.234 +  }
   3.235 +  return entry;
   3.236 +}
   3.237 +
   3.238 +ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, oop protection_domain) {
   3.239 +  for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) {
   3.240 +    if (e->protection_domain() == protection_domain) {
   3.241 +      return e;
   3.242 +    }
   3.243 +  }
   3.244 +
   3.245 +  return NULL;
   3.246 +}
   3.247 +
   3.248 +ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, oop protection_domain) {
   3.249 +  assert_locked_or_safepoint(SystemDictionary_lock);
   3.250 +  assert(index == index_for(protection_domain), "incorrect index?");
   3.251 +  assert(find_entry(index, protection_domain) == NULL, "no double entry");
   3.252 +
   3.253 +  ProtectionDomainCacheEntry* p = new_entry(hash, protection_domain);
   3.254 +  Hashtable<oop, mtClass>::add_entry(index, p);
   3.255 +  return p;
   3.256 +}
   3.257 +
   3.258 +void ProtectionDomainCacheTable::free(ProtectionDomainCacheEntry* to_delete) {
   3.259 +  unsigned int hash = compute_hash(to_delete->protection_domain());
   3.260 +  int index = hash_to_index(hash);
   3.261 +
   3.262 +  ProtectionDomainCacheEntry** p = bucket_addr(index);
   3.263 +  ProtectionDomainCacheEntry* entry = bucket(index);
   3.264 +  while (true) {
   3.265 +    assert(entry != NULL, "sanity");
   3.266 +
   3.267 +    if (entry == to_delete) {
   3.268 +      *p = entry->next();
   3.269 +      Hashtable<oop, mtClass>::free_entry(entry);
   3.270 +      break;
   3.271 +    } else {
   3.272 +      p = entry->next_addr();
   3.273 +      entry = *p;
   3.274 +    }
   3.275 +  }
   3.276 +}
   3.277 +
   3.278  SymbolPropertyTable::SymbolPropertyTable(int table_size)
   3.279    : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry))
   3.280  {
   3.281 @@ -532,11 +682,13 @@
   3.282        tty->cr();
   3.283      }
   3.284    }
   3.285 +  tty->cr();
   3.286 +  _pd_cache_table->print();
   3.287 +  tty->cr();
   3.288  }
   3.289  
   3.290  #endif
   3.291  
   3.292 -
   3.293  void Dictionary::verify() {
   3.294    guarantee(number_of_entries() >= 0, "Verify of system dictionary failed");
   3.295  
   3.296 @@ -563,5 +715,7 @@
   3.297    guarantee(number_of_entries() == element_count,
   3.298              "Verify of system dictionary failed");
   3.299    debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
   3.300 +
   3.301 +  _pd_cache_table->verify();
   3.302  }
   3.303  
     4.1 --- a/src/share/vm/classfile/dictionary.hpp	Wed Oct 09 11:18:53 2013 -0700
     4.2 +++ b/src/share/vm/classfile/dictionary.hpp	Wed Oct 09 10:57:01 2013 +0200
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -27,11 +27,14 @@
    4.11  
    4.12  #include "classfile/systemDictionary.hpp"
    4.13  #include "oops/instanceKlass.hpp"
    4.14 -#include "oops/oop.hpp"
    4.15 +#include "oops/oop.inline.hpp"
    4.16  #include "utilities/hashtable.hpp"
    4.17  
    4.18  class DictionaryEntry;
    4.19  class PSPromotionManager;
    4.20 +class ProtectionDomainCacheTable;
    4.21 +class ProtectionDomainCacheEntry;
    4.22 +class BoolObjectClosure;
    4.23  
    4.24  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4.25  // The data structure for the system dictionary (and the shared system
    4.26 @@ -45,6 +48,8 @@
    4.27    // pointer to the current hash table entry.
    4.28    static DictionaryEntry*       _current_class_entry;
    4.29  
    4.30 +  ProtectionDomainCacheTable*   _pd_cache_table;
    4.31 +
    4.32    DictionaryEntry* get_entry(int index, unsigned int hash,
    4.33                               Symbol* name, ClassLoaderData* loader_data);
    4.34  
    4.35 @@ -93,6 +98,7 @@
    4.36  
    4.37    void methods_do(void f(Method*));
    4.38  
    4.39 +  void unlink(BoolObjectClosure* is_alive);
    4.40  
    4.41    // Classes loaded by the bootstrap loader are always strongly reachable.
    4.42    // If we're not doing class unloading, all classes are strongly reachable.
    4.43 @@ -118,6 +124,7 @@
    4.44    // Sharing support
    4.45    void reorder_dictionary();
    4.46  
    4.47 +  ProtectionDomainCacheEntry* cache_get(oop protection_domain);
    4.48  
    4.49  #ifndef PRODUCT
    4.50    void print();
    4.51 @@ -126,21 +133,112 @@
    4.52  };
    4.53  
    4.54  // The following classes can be in dictionary.cpp, but we need these
    4.55 -// to be in header file so that SA's vmStructs can access.
    4.56 +// to be in header file so that SA's vmStructs can access them.
    4.57 +class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
    4.58 +  friend class VMStructs;
    4.59 + private:
    4.60 +  // Flag indicating whether this protection domain entry is strongly reachable.
    4.61 +  // Used during iterating over the system dictionary to remember oops that need
    4.62 +  // to be updated.
    4.63 +  bool _strongly_reachable;
    4.64 + public:
    4.65 +  oop protection_domain() { return literal(); }
    4.66 +
    4.67 +  void init() {
    4.68 +    _strongly_reachable = false;
    4.69 +  }
    4.70 +
    4.71 +  ProtectionDomainCacheEntry* next() {
    4.72 +    return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
    4.73 +  }
    4.74 +
    4.75 +  ProtectionDomainCacheEntry** next_addr() {
    4.76 +    return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
    4.77 +  }
    4.78 +
    4.79 +  void oops_do(OopClosure* f) {
    4.80 +    f->do_oop(literal_addr());
    4.81 +  }
    4.82 +
    4.83 +  void set_strongly_reachable()   { _strongly_reachable = true; }
    4.84 +  bool is_strongly_reachable()    { return _strongly_reachable; }
    4.85 +  void reset_strongly_reachable() { _strongly_reachable = false; }
    4.86 +
    4.87 +  void print() PRODUCT_RETURN;
    4.88 +  void verify();
    4.89 +};
    4.90 +
    4.91 +// The ProtectionDomainCacheTable contains all protection domain oops. The system
    4.92 +// dictionary entries reference its entries instead of having references to oops
    4.93 +// directly.
    4.94 +// This is used to speed up system dictionary iteration: the oops in the
    4.95 +// protection domain are the only ones referring the Java heap. So when there is
    4.96 +// need to update these, instead of going over every entry of the system dictionary,
    4.97 +// we only need to iterate over this set.
    4.98 +// The amount of different protection domains used is typically magnitudes smaller
    4.99 +// than the number of system dictionary entries (loaded classes).
   4.100 +class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
   4.101 +  friend class VMStructs;
   4.102 +private:
   4.103 +  ProtectionDomainCacheEntry* bucket(int i) {
   4.104 +    return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
   4.105 +  }
   4.106 +
   4.107 +  // The following method is not MT-safe and must be done under lock.
   4.108 +  ProtectionDomainCacheEntry** bucket_addr(int i) {
   4.109 +    return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
   4.110 +  }
   4.111 +
   4.112 +  ProtectionDomainCacheEntry* new_entry(unsigned int hash, oop protection_domain) {
   4.113 +    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain);
   4.114 +    entry->init();
   4.115 +    return entry;
   4.116 +  }
   4.117 +
   4.118 +  static unsigned int compute_hash(oop protection_domain) {
   4.119 +    return (unsigned int)(protection_domain->identity_hash());
   4.120 +  }
   4.121 +
   4.122 +  int index_for(oop protection_domain) {
   4.123 +    return hash_to_index(compute_hash(protection_domain));
   4.124 +  }
   4.125 +
   4.126 +  ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, oop protection_domain);
   4.127 +  ProtectionDomainCacheEntry* find_entry(int index, oop protection_domain);
   4.128 +
   4.129 +public:
   4.130 +
   4.131 +  ProtectionDomainCacheTable(int table_size);
   4.132 +
   4.133 +  ProtectionDomainCacheEntry* get(oop protection_domain);
   4.134 +  void free(ProtectionDomainCacheEntry* entry);
   4.135 +
   4.136 +  void unlink(BoolObjectClosure* cl);
   4.137 +
   4.138 +  // GC support
   4.139 +  void oops_do(OopClosure* f);
   4.140 +  void always_strong_oops_do(OopClosure* f);
   4.141 +
   4.142 +  static uint bucket_size();
   4.143 +
   4.144 +  void print() PRODUCT_RETURN;
   4.145 +  void verify();
   4.146 +};
   4.147 +
   4.148  
   4.149  class ProtectionDomainEntry :public CHeapObj<mtClass> {
   4.150    friend class VMStructs;
   4.151   public:
   4.152    ProtectionDomainEntry* _next;
   4.153 -  oop                    _protection_domain;
   4.154 +  ProtectionDomainCacheEntry* _pd_cache;
   4.155  
   4.156 -  ProtectionDomainEntry(oop protection_domain, ProtectionDomainEntry* next) {
   4.157 -    _protection_domain = protection_domain;
   4.158 -    _next              = next;
   4.159 +  ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
   4.160 +    _pd_cache = pd_cache;
   4.161 +    _next     = next;
   4.162    }
   4.163  
   4.164    ProtectionDomainEntry* next() { return _next; }
   4.165 -  oop protection_domain() { return _protection_domain; }
   4.166 +  oop protection_domain() { return _pd_cache->protection_domain(); }
   4.167  };
   4.168  
   4.169  // An entry in the system dictionary, this describes a class as
   4.170 @@ -151,6 +249,24 @@
   4.171   private:
   4.172    // Contains the set of approved protection domains that can access
   4.173    // this system dictionary entry.
   4.174 +  //
   4.175 +  // This protection domain set is a set of tuples:
   4.176 +  //
   4.177 +  // (InstanceKlass C, initiating class loader ICL, Protection Domain PD)
   4.178 +  //
   4.179 +  // [Note that C.protection_domain(), which is stored in the java.lang.Class
   4.180 +  // mirror of C, is NOT the same as PD]
   4.181 +  //
   4.182 +  // If such an entry (C, ICL, PD) exists in the table, it means that
   4.183 +  // it is okay for a class Foo to reference C, where
   4.184 +  //
   4.185 +  //    Foo.protection_domain() == PD, and
   4.186 +  //    Foo's defining class loader == ICL
   4.187 +  //
   4.188 +  // The usage of the PD set can be seen in SystemDictionary::validate_protection_domain()
   4.189 +  // It is essentially a cache to avoid repeated Java up-calls to
   4.190 +  // ClassLoader.checkPackageAccess().
   4.191 +  //
   4.192    ProtectionDomainEntry* _pd_set;
   4.193    ClassLoaderData*       _loader_data;
   4.194  
   4.195 @@ -158,7 +274,7 @@
   4.196    // Tells whether a protection is in the approved set.
   4.197    bool contains_protection_domain(oop protection_domain) const;
   4.198    // Adds a protection domain to the approved set.
   4.199 -  void add_protection_domain(oop protection_domain);
   4.200 +  void add_protection_domain(Dictionary* dict, oop protection_domain);
   4.201  
   4.202    Klass* klass() const { return (Klass*)literal(); }
   4.203    Klass** klass_addr() { return (Klass**)literal_addr(); }
   4.204 @@ -189,12 +305,11 @@
   4.205           : contains_protection_domain(protection_domain());
   4.206    }
   4.207  
   4.208 -
   4.209 -  void protection_domain_set_oops_do(OopClosure* f) {
   4.210 +  void set_strongly_reachable() {
   4.211      for (ProtectionDomainEntry* current = _pd_set;
   4.212                                  current != NULL;
   4.213                                  current = current->_next) {
   4.214 -      f->do_oop(&(current->_protection_domain));
   4.215 +      current->_pd_cache->set_strongly_reachable();
   4.216      }
   4.217    }
   4.218  
   4.219 @@ -202,7 +317,7 @@
   4.220      for (ProtectionDomainEntry* current = _pd_set;
   4.221                                  current != NULL;
   4.222                                  current = current->_next) {
   4.223 -      current->_protection_domain->verify();
   4.224 +      current->_pd_cache->protection_domain()->verify();
   4.225      }
   4.226    }
   4.227  
     5.1 --- a/src/share/vm/classfile/systemDictionary.cpp	Wed Oct 09 11:18:53 2013 -0700
     5.2 +++ b/src/share/vm/classfile/systemDictionary.cpp	Wed Oct 09 10:57:01 2013 +0200
     5.3 @@ -1697,6 +1697,24 @@
     5.4    return newsize;
     5.5  }
     5.6  
     5.7 +#ifdef ASSERT
     5.8 +class VerifySDReachableAndLiveClosure : public OopClosure {
     5.9 +private:
    5.10 +  BoolObjectClosure* _is_alive;
    5.11 +
    5.12 +  template <class T> void do_oop_work(T* p) {
    5.13 +    oop obj = oopDesc::load_decode_heap_oop(p);
    5.14 +    guarantee(_is_alive->do_object_b(obj), "Oop in system dictionary must be live");
    5.15 +  }
    5.16 +
    5.17 +public:
    5.18 +  VerifySDReachableAndLiveClosure(BoolObjectClosure* is_alive) : OopClosure(), _is_alive(is_alive) { }
    5.19 +
    5.20 +  virtual void do_oop(oop* p)       { do_oop_work(p); }
    5.21 +  virtual void do_oop(narrowOop* p) { do_oop_work(p); }
    5.22 +};
    5.23 +#endif
    5.24 +
    5.25  // Assumes classes in the SystemDictionary are only unloaded at a safepoint
    5.26  // Note: anonymous classes are not in the SD.
    5.27  bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) {
    5.28 @@ -1707,7 +1725,15 @@
    5.29      unloading_occurred = dictionary()->do_unloading();
    5.30      constraints()->purge_loader_constraints();
    5.31      resolution_errors()->purge_resolution_errors();
    5.32 -}
    5.33 +  }
    5.34 +  // Oops referenced by the system dictionary may get unreachable independently
    5.35 +  // of the class loader (eg. cached protection domain oops). So we need to
    5.36 +  // explicitly unlink them here instead of in Dictionary::do_unloading.
    5.37 +  dictionary()->unlink(is_alive);
    5.38 +#ifdef ASSERT
    5.39 +  VerifySDReachableAndLiveClosure cl(is_alive);
    5.40 +  dictionary()->oops_do(&cl);
    5.41 +#endif
    5.42    return unloading_occurred;
    5.43  }
    5.44  
     6.1 --- a/src/share/vm/runtime/vmStructs.cpp	Wed Oct 09 11:18:53 2013 -0700
     6.2 +++ b/src/share/vm/runtime/vmStructs.cpp	Wed Oct 09 10:57:01 2013 +0200
     6.3 @@ -714,11 +714,17 @@
     6.4    nonstatic_field(PlaceholderEntry,            _loader_data,                                  ClassLoaderData*)                      \
     6.5                                                                                                                                       \
     6.6    /**************************/                                                                                                       \
     6.7 -  /* ProctectionDomainEntry */                                                                                                       \
     6.8 +  /* ProtectionDomainEntry  */                                                                                                       \
     6.9    /**************************/                                                                                                       \
    6.10                                                                                                                                       \
    6.11    nonstatic_field(ProtectionDomainEntry,       _next,                                         ProtectionDomainEntry*)                \
    6.12 -  nonstatic_field(ProtectionDomainEntry,       _protection_domain,                            oop)                                   \
    6.13 +  nonstatic_field(ProtectionDomainEntry,       _pd_cache,                                     ProtectionDomainCacheEntry*)           \
    6.14 +                                                                                                                                     \
    6.15 +  /*******************************/                                                                                                  \
    6.16 +  /* ProtectionDomainCacheEntry  */                                                                                                  \
    6.17 +  /*******************************/                                                                                                  \
    6.18 +                                                                                                                                     \
    6.19 +  nonstatic_field(ProtectionDomainCacheEntry,  _literal,                                      oop)                                   \
    6.20                                                                                                                                       \
    6.21    /*************************/                                                                                                        \
    6.22    /* LoaderConstraintEntry */                                                                                                        \
    6.23 @@ -1560,6 +1566,7 @@
    6.24    declare_toplevel_type(SystemDictionary)                                 \
    6.25    declare_toplevel_type(vmSymbols)                                        \
    6.26    declare_toplevel_type(ProtectionDomainEntry)                            \
    6.27 +  declare_toplevel_type(ProtectionDomainCacheEntry)                       \
    6.28                                                                            \
    6.29    declare_toplevel_type(GenericGrowableArray)                             \
    6.30    declare_toplevel_type(GrowableArray<int>)                               \
     7.1 --- a/src/share/vm/utilities/globalDefinitions.hpp	Wed Oct 09 11:18:53 2013 -0700
     7.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp	Wed Oct 09 10:57:01 2013 +0200
     7.3 @@ -326,12 +326,15 @@
     7.4  
     7.5  const int max_method_code_size = 64*K - 1;  // JVM spec, 2nd ed. section 4.8.1 (p.134)
     7.6  
     7.7 +// Default ProtectionDomainCacheSize values
     7.8 +
     7.9 +const int defaultProtectionDomainCacheSize = NOT_LP64(137) LP64_ONLY(2017);
    7.10  
    7.11  //----------------------------------------------------------------------------------------------------
    7.12  // Default and minimum StringTableSize values
    7.13  
    7.14  const int defaultStringTableSize = NOT_LP64(1009) LP64_ONLY(60013);
    7.15 -const int minimumStringTableSize=1009;
    7.16 +const int minimumStringTableSize = 1009;
    7.17  
    7.18  
    7.19  //----------------------------------------------------------------------------------------------------

mercurial