hotspot/src/share/vm/classfile/protectionDomainCache.hpp
changeset 46554 aa1cfd918c4f
parent 46382 5520c435279b
child 46729 c62d2e8b2728
equal deleted inserted replaced
45608:9927a9f16738 46554:aa1cfd918c4f
       
     1 /*
       
     2  * Copyright (c) 2017, 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  *
       
    23  */
       
    24 
       
    25 #ifndef SHARE_VM_CLASSFILE_PROTECTIONDOMAINCACHE_HPP
       
    26 #define SHARE_VM_CLASSFILE_PROTECTIONDOMAINCACHE_HPP
       
    27 
       
    28 #include "oops/oop.hpp"
       
    29 #include "memory/iterator.hpp"
       
    30 #include "utilities/hashtable.hpp"
       
    31 
       
    32 // This class caches the approved protection domains that can access loaded classes.
       
    33 // Dictionary entry pd_set point to entries in this hashtable.   Please refer
       
    34 // to dictionary.hpp pd_set for more information about how protection domain entries
       
    35 // are used.
       
    36 // This table is walked during GC, rather than the entire system dictionary
       
    37 class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
       
    38   friend class VMStructs;
       
    39  public:
       
    40   oop protection_domain() { return literal(); }
       
    41 
       
    42   ProtectionDomainCacheEntry* next() {
       
    43     return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
       
    44   }
       
    45 
       
    46   ProtectionDomainCacheEntry** next_addr() {
       
    47     return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
       
    48   }
       
    49 
       
    50   void oops_do(OopClosure* f) {
       
    51     f->do_oop(literal_addr());
       
    52   }
       
    53 
       
    54   void print() PRODUCT_RETURN;
       
    55   void verify();
       
    56 };
       
    57 
       
    58 // The ProtectionDomainCacheTable contains all protection domain oops. The system
       
    59 // dictionary entries reference its entries instead of having references to oops
       
    60 // directly.
       
    61 // This is used to speed up system dictionary iteration: the oops in the
       
    62 // protection domain are the only ones referring the Java heap. So when there is
       
    63 // need to update these, instead of going over every entry of the system dictionary,
       
    64 // we only need to iterate over this set.
       
    65 // The amount of different protection domains used is typically magnitudes smaller
       
    66 // than the number of system dictionary entries (loaded classes).
       
    67 class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
       
    68   friend class VMStructs;
       
    69 private:
       
    70   ProtectionDomainCacheEntry* bucket(int i) {
       
    71     return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
       
    72   }
       
    73 
       
    74   // The following method is not MT-safe and must be done under lock.
       
    75   ProtectionDomainCacheEntry** bucket_addr(int i) {
       
    76     return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
       
    77   }
       
    78 
       
    79   ProtectionDomainCacheEntry* new_entry(unsigned int hash, Handle protection_domain) {
       
    80     ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain());
       
    81     return entry;
       
    82   }
       
    83 
       
    84   static unsigned int compute_hash(Handle protection_domain);
       
    85 
       
    86   int index_for(Handle protection_domain);
       
    87   ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, Handle protection_domain);
       
    88   ProtectionDomainCacheEntry* find_entry(int index, Handle protection_domain);
       
    89 
       
    90 public:
       
    91   ProtectionDomainCacheTable(int table_size);
       
    92   ProtectionDomainCacheEntry* get(Handle protection_domain);
       
    93 
       
    94   void unlink(BoolObjectClosure* cl);
       
    95 
       
    96   // GC support
       
    97   void oops_do(OopClosure* f);
       
    98 
       
    99   void print() PRODUCT_RETURN;
       
   100   void verify();
       
   101 };
       
   102 
       
   103 
       
   104 class ProtectionDomainEntry :public CHeapObj<mtClass> {
       
   105   friend class VMStructs;
       
   106  public:
       
   107   ProtectionDomainEntry* _next;
       
   108   ProtectionDomainCacheEntry* _pd_cache;
       
   109 
       
   110   ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
       
   111     _pd_cache = pd_cache;
       
   112     _next     = next;
       
   113   }
       
   114 
       
   115   ProtectionDomainEntry* next() { return _next; }
       
   116   oop protection_domain() { return _pd_cache->protection_domain(); }
       
   117 };
       
   118 #endif // SHARE_VM_CLASSFILE_PROTECTIONDOMAINCACHE_HPP