src/hotspot/share/classfile/protectionDomainCache.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 58177 4932dce35882
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
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
/*
53962
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
46382
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
#include "precompiled.hpp"
53962
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    26
#include "classfile/classLoaderDataGraph.hpp"
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    27
#include "classfile/dictionary.hpp"
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    28
#include "classfile/protectionDomainCache.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    29
#include "classfile/systemDictionary.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
    30
#include "logging/log.hpp"
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
    31
#include "logging/logStream.hpp"
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    32
#include "memory/iterator.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    33
#include "memory/resourceArea.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    34
#include "oops/oop.inline.hpp"
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
    35
#include "oops/weakHandle.inline.hpp"
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    36
#include "utilities/hashtable.inline.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    37
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    38
unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    39
  // Identity hash can safepoint, so keep protection domain in a Handle.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    40
  return (unsigned int)(protection_domain->identity_hash());
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
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    43
int ProtectionDomainCacheTable::index_for(Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    44
  return hash_to_index(compute_hash(protection_domain));
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
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    47
ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size)
54419
5c7418757bad 8221872: Remove uses of ClassLoaderWeakHandle typedef in protection domain table
coleenp
parents: 53962
diff changeset
    48
  : Hashtable<WeakHandle<vm_class_loader_data>, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    49
{   _dead_entries = false;
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    50
    _total_oops_removed = 0;
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    51
}
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    52
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    53
void ProtectionDomainCacheTable::trigger_cleanup() {
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 54419
diff changeset
    54
  MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    55
  _dead_entries = true;
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    56
  Service_lock->notify_all();
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    57
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    58
53962
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    59
class CleanProtectionDomainEntries : public CLDClosure {
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    60
  void do_cld(ClassLoaderData* data) {
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    61
    Dictionary* dictionary = data->dictionary();
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    62
    if (dictionary != NULL) {
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    63
      dictionary->clean_cached_protection_domains();
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    64
    }
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    65
  }
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    66
};
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    67
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
    68
void ProtectionDomainCacheTable::unlink() {
53962
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    69
  {
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    70
    // First clean cached pd lists in loaded CLDs
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    71
    // It's unlikely, but some loaded classes in a dictionary might
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    72
    // point to a protection_domain that has been unloaded.
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    73
    // The dictionary pd_set points at entries in the ProtectionDomainCacheTable.
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    74
    MutexLocker ml(ClassLoaderDataGraph_lock);
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    75
    MutexLocker mldict(SystemDictionary_lock);  // need both.
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    76
    CleanProtectionDomainEntries clean;
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    77
    ClassLoaderDataGraph::loaded_cld_do(&clean);
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    78
  }
2653e078b057 8218266: G1 crash in AccessInternal::PostRuntimeDispatch
coleenp
parents: 51610
diff changeset
    79
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    80
  MutexLocker ml(SystemDictionary_lock);
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    81
  int oops_removed = 0;
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    82
  for (int i = 0; i < table_size(); ++i) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    83
    ProtectionDomainCacheEntry** p = bucket_addr(i);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    84
    ProtectionDomainCacheEntry* entry = bucket(i);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    85
    while (entry != NULL) {
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
    86
      oop pd = entry->object_no_keepalive();
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
    87
      if (pd != NULL) {
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    88
        p = entry->next_addr();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    89
      } else {
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    90
        oops_removed++;
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
    91
        LogTarget(Debug, protectiondomain, table) lt;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
    92
        if (lt.is_enabled()) {
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46475
diff changeset
    93
          LogStream ls(lt);
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
    94
          ls.print_cr("protection domain unlinked at %d", i);
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    95
        }
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
    96
        entry->literal().release();
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    97
        *p = entry->next();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    98
        free_entry(entry);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    99
      }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   100
      entry = *p;
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
  }
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   103
  _total_oops_removed += oops_removed;
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   104
  _dead_entries = false;
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   105
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   106
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   107
void ProtectionDomainCacheTable::print_on(outputStream* st) const {
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   108
  assert_locked_or_safepoint(SystemDictionary_lock);
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   109
  st->print_cr("Protection domain cache table (table_size=%d, classes=%d)",
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46729
diff changeset
   110
               table_size(), number_of_entries());
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   111
  for (int index = 0; index < table_size(); index++) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   112
    for (ProtectionDomainCacheEntry* probe = bucket(index);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   113
                                     probe != NULL;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   114
                                     probe = probe->next()) {
48781
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   115
      st->print_cr("%4d: protection_domain: " PTR_FORMAT, index, p2i(probe->object_no_keepalive()));
46382
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
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   118
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   119
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   120
void ProtectionDomainCacheTable::verify() {
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   121
  verify_table<ProtectionDomainCacheEntry>("Protection Domain Table");
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   122
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   123
48781
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   124
oop ProtectionDomainCacheEntry::object() {
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   125
  return literal().resolve();
48781
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   126
}
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   127
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   128
oop ProtectionDomainEntry::object() {
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   129
  return _pd_cache->object();
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   130
}
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   131
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   132
// The object_no_keepalive() call peeks at the phantomly reachable oop without
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   133
// keeping it alive. This is okay to do in the VM thread state if it is not
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   134
// leaked out to become strongly reachable.
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   135
oop ProtectionDomainCacheEntry::object_no_keepalive() {
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   136
  return literal().peek();
48781
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   137
}
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   138
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   139
oop ProtectionDomainEntry::object_no_keepalive() {
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   140
  return _pd_cache->object_no_keepalive();
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   141
}
6ebef5cd0c8d 8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents: 47216
diff changeset
   142
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   143
void ProtectionDomainCacheEntry::verify() {
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   144
  guarantee(object_no_keepalive() == NULL || oopDesc::is_oop(object_no_keepalive()), "must be an oop");
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   145
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   146
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   147
ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   148
  unsigned int hash = compute_hash(protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   149
  int index = hash_to_index(hash);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   150
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   151
  ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   152
  if (entry == NULL) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   153
    entry = add_entry(index, hash, protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   154
  }
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   155
  // keep entry alive
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   156
  (void)entry->object();
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   157
  return entry;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   158
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   159
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   160
ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, Handle protection_domain) {
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   161
  assert_locked_or_safepoint(SystemDictionary_lock);
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   162
  for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) {
58177
4932dce35882 8230841: Remove oopDesc::equals()
pliden
parents: 54623
diff changeset
   163
    if (e->object_no_keepalive() == protection_domain()) {
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   164
      return e;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   165
    }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   166
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   167
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   168
  return NULL;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   169
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   170
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   171
ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   172
  assert_locked_or_safepoint(SystemDictionary_lock);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   173
  assert(index == index_for(protection_domain), "incorrect index?");
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   174
  assert(find_entry(index, protection_domain) == NULL, "no double entry");
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   175
51610
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   176
  LogTarget(Debug, protectiondomain, table) lt;
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   177
  if (lt.is_enabled()) {
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   178
    LogStream ls(lt);
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   179
    ls.print("protection domain added ");
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   180
    protection_domain->print_value_on(&ls);
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   181
    ls.cr();
cdef4df6b0e7 8206424: Use locking for cleaning ProtectionDomainTable
pchilanomate
parents: 49818
diff changeset
   182
  }
54419
5c7418757bad 8221872: Remove uses of ClassLoaderWeakHandle typedef in protection domain table
coleenp
parents: 53962
diff changeset
   183
  WeakHandle<vm_class_loader_data> w = WeakHandle<vm_class_loader_data>::create(protection_domain);
49818
e57e6addb978 8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents: 49658
diff changeset
   184
  ProtectionDomainCacheEntry* p = new_entry(hash, w);
54419
5c7418757bad 8221872: Remove uses of ClassLoaderWeakHandle typedef in protection domain table
coleenp
parents: 53962
diff changeset
   185
  Hashtable<WeakHandle<vm_class_loader_data>, mtClass>::add_entry(index, p);
46382
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   186
  return p;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   187
}