src/hotspot/share/classfile/protectionDomainCache.hpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46742 hotspot/src/share/vm/classfile/protectionDomainCache.hpp@24ec8a039c90
child 48781 6ebef5cd0c8d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     1
/*
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     4
 *
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     8
 *
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    13
 * accompanied this code).
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    14
 *
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    18
 *
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    21
 * questions.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    22
 *
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    23
 */
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    24
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_PROTECTIONDOMAINCACHE_HPP
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_PROTECTIONDOMAINCACHE_HPP
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    27
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    28
#include "oops/oop.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    29
#include "memory/iterator.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    30
#include "utilities/hashtable.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    31
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    32
// This class caches the approved protection domains that can access loaded classes.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    33
// Dictionary entry pd_set point to entries in this hashtable.   Please refer
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    34
// to dictionary.hpp pd_set for more information about how protection domain entries
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    35
// are used.
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46382
diff changeset
    36
// This table is walked during GC, rather than the class loader data graph dictionaries.
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    37
class ProtectionDomainCacheEntry : public HashtableEntry<oop, mtClass> {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    38
  friend class VMStructs;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    39
 public:
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    40
  oop protection_domain() { return literal(); }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    41
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    42
  ProtectionDomainCacheEntry* next() {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    43
    return (ProtectionDomainCacheEntry*)HashtableEntry<oop, mtClass>::next();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    44
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    45
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    46
  ProtectionDomainCacheEntry** next_addr() {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    47
    return (ProtectionDomainCacheEntry**)HashtableEntry<oop, mtClass>::next_addr();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    48
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    49
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    50
  void oops_do(OopClosure* f) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    51
    f->do_oop(literal_addr());
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    52
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    53
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    54
  void verify();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    55
};
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    56
46729
c62d2e8b2728 7133093: Improve system dictionary performance
coleenp
parents: 46382
diff changeset
    57
// The ProtectionDomainCacheTable contains all protection domain oops. The
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    58
// dictionary entries reference its entries instead of having references to oops
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    59
// directly.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    60
// This is used to speed up system dictionary iteration: the oops in the
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    61
// protection domain are the only ones referring the Java heap. So when there is
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    62
// need to update these, instead of going over every entry of the system dictionary,
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    63
// we only need to iterate over this set.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    64
// The amount of different protection domains used is typically magnitudes smaller
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    65
// than the number of system dictionary entries (loaded classes).
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    66
class ProtectionDomainCacheTable : public Hashtable<oop, mtClass> {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    67
  friend class VMStructs;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    68
private:
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
    69
  ProtectionDomainCacheEntry* bucket(int i) const {
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    70
    return (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::bucket(i);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    71
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    72
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    73
  // The following method is not MT-safe and must be done under lock.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    74
  ProtectionDomainCacheEntry** bucket_addr(int i) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    75
    return (ProtectionDomainCacheEntry**) Hashtable<oop, mtClass>::bucket_addr(i);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    76
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    77
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    78
  ProtectionDomainCacheEntry* new_entry(unsigned int hash, Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    79
    ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*) Hashtable<oop, mtClass>::new_entry(hash, protection_domain());
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    80
    return entry;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    81
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    82
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    83
  static unsigned int compute_hash(Handle protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    84
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    85
  int index_for(Handle protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    86
  ProtectionDomainCacheEntry* add_entry(int index, unsigned int hash, Handle protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    87
  ProtectionDomainCacheEntry* find_entry(int index, Handle protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    88
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    89
public:
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    90
  ProtectionDomainCacheTable(int table_size);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    91
  ProtectionDomainCacheEntry* get(Handle protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    92
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    93
  void unlink(BoolObjectClosure* cl);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    94
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    95
  // GC support
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    96
  void oops_do(OopClosure* f);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    97
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
    98
  void print_on(outputStream* st) const;
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    99
  void verify();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   100
};
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   101
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   102
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   103
class ProtectionDomainEntry :public CHeapObj<mtClass> {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   104
  friend class VMStructs;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   105
 public:
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   106
  ProtectionDomainEntry* _next;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   107
  ProtectionDomainCacheEntry* _pd_cache;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   108
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   109
  ProtectionDomainEntry(ProtectionDomainCacheEntry* pd_cache, ProtectionDomainEntry* next) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   110
    _pd_cache = pd_cache;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   111
    _next     = next;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   112
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   113
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   114
  ProtectionDomainEntry* next() { return _next; }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   115
  oop protection_domain() { return _pd_cache->protection_domain(); }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   116
};
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   117
#endif // SHARE_VM_CLASSFILE_PROTECTIONDOMAINCACHE_HPP