hotspot/src/share/vm/classfile/protectionDomainCache.cpp
author coleenp
Thu, 18 May 2017 08:17:52 -0400
changeset 46475 75902cea18af
parent 46382 5520c435279b
child 46701 f559541c0daa
permissions -rw-r--r--
8166848: Performance bug: SystemDictionary - optimization Summary: Check instead that a bucket isn't 10x the average Reviewed-by: iklam, gziemski, sspitsyn
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
#include "precompiled.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    26
#include "classfile/protectionDomainCache.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    27
#include "classfile/systemDictionary.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    28
#include "memory/iterator.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    29
#include "memory/resourceArea.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    30
#include "oops/oop.inline.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    31
#include "utilities/hashtable.inline.hpp"
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    32
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    33
unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    34
  // Identity hash can safepoint, so keep protection domain in a Handle.
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    35
  return (unsigned int)(protection_domain->identity_hash());
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    36
}
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
int ProtectionDomainCacheTable::index_for(Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    39
  return hash_to_index(compute_hash(protection_domain));
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    40
}
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
ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size)
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    43
  : Hashtable<oop, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
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
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    47
void ProtectionDomainCacheTable::unlink(BoolObjectClosure* is_alive) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    48
  assert(SafepointSynchronize::is_at_safepoint(), "must be");
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    49
  for (int i = 0; i < table_size(); ++i) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    50
    ProtectionDomainCacheEntry** p = bucket_addr(i);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    51
    ProtectionDomainCacheEntry* entry = bucket(i);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    52
    while (entry != NULL) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    53
      if (is_alive->do_object_b(entry->literal())) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    54
        p = entry->next_addr();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    55
      } else {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    56
        if (log_is_enabled(Debug, protectiondomain)) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    57
          outputStream* log = Log(protectiondomain)::debug_stream();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    58
          log->print("protection domain unlinked: ");
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    59
          entry->literal()->print_value_on(log);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    60
          log->cr();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    61
        }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    62
        *p = entry->next();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    63
        free_entry(entry);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    64
      }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    65
      entry = *p;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    66
    }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    67
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    68
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    69
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    70
void ProtectionDomainCacheTable::oops_do(OopClosure* f) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    71
  for (int index = 0; index < table_size(); index++) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    72
    for (ProtectionDomainCacheEntry* probe = bucket(index);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    73
                                     probe != NULL;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    74
                                     probe = probe->next()) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    75
      probe->oops_do(f);
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
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    79
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    80
#ifndef PRODUCT
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    81
void ProtectionDomainCacheTable::print() {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    82
  tty->print_cr("Protection domain cache table (table_size=%d, classes=%d)",
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    83
                table_size(), number_of_entries());
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    84
  for (int index = 0; index < table_size(); index++) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    85
    for (ProtectionDomainCacheEntry* probe = bucket(index);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    86
                                     probe != NULL;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    87
                                     probe = probe->next()) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    88
      probe->print();
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    89
    }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    90
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    91
}
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 ProtectionDomainCacheEntry::print() {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    94
  tty->print_cr("entry " PTR_FORMAT " value " PTR_FORMAT " next " PTR_FORMAT,
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    95
                p2i(this), p2i(literal()), p2i(next()));
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    96
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    97
#endif
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    98
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
    99
void ProtectionDomainCacheTable::verify() {
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46382
diff changeset
   100
  verify_table<ProtectionDomainCacheEntry>("Protection Domain Table");
46382
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
void ProtectionDomainCacheEntry::verify() {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   104
  guarantee(literal()->is_oop(), "must be an oop");
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
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   107
ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   108
  unsigned int hash = compute_hash(protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   109
  int index = hash_to_index(hash);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   110
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   111
  ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   112
  if (entry == NULL) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   113
    entry = add_entry(index, hash, protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   114
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   115
  return entry;
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
ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, Handle protection_domain) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   119
  for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   120
    if (e->protection_domain() == protection_domain()) {
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   121
      return e;
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
  }
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   124
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   125
  return NULL;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   126
}
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   127
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   128
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
   129
  assert_locked_or_safepoint(SystemDictionary_lock);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   130
  assert(index == index_for(protection_domain), "incorrect index?");
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   131
  assert(find_entry(index, protection_domain) == NULL, "no double entry");
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   132
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   133
  ProtectionDomainCacheEntry* p = new_entry(hash, protection_domain);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   134
  Hashtable<oop, mtClass>::add_entry(index, p);
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   135
  return p;
5520c435279b 8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
diff changeset
   136
}