annotate src/share/vm/classfile/protectionDomainCache.cpp @ 13365:ff28370e679e

8181917: Refactor UL LogStreams to avoid using resource area Reviewed-by: ehelin, mlarsson
author stuefe
date Fri, 21 Jul 2017 09:50:12 +0200
parents b8b1c646f132
children 46bb2774fc88
rev   line source
coleenp@12855 1 /*
coleenp@12855 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
coleenp@12855 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@12855 4 *
coleenp@12855 5 * This code is free software; you can redistribute it and/or modify it
coleenp@12855 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@12855 7 * published by the Free Software Foundation.
coleenp@12855 8 *
coleenp@12855 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@12855 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
coleenp@12855 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@12855 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@12855 13 * accompanied this code).
coleenp@12855 14 *
coleenp@12855 15 * You should have received a copy of the GNU General Public License version
coleenp@12855 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@12855 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@12855 18 *
coleenp@12855 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@12855 20 * or visit www.oracle.com if you need additional information or have any
coleenp@12855 21 * questions.
coleenp@12855 22 *
coleenp@12855 23 */
coleenp@12855 24
coleenp@12855 25 #include "precompiled.hpp"
coleenp@12855 26 #include "classfile/protectionDomainCache.hpp"
coleenp@12855 27 #include "classfile/systemDictionary.hpp"
stuefe@13365 28 #include "logging/log.hpp"
stuefe@13365 29 #include "logging/logStream.hpp"
coleenp@12855 30 #include "memory/iterator.hpp"
coleenp@12855 31 #include "memory/resourceArea.hpp"
coleenp@12855 32 #include "oops/oop.inline.hpp"
coleenp@12855 33 #include "utilities/hashtable.inline.hpp"
coleenp@12855 34
coleenp@12855 35 unsigned int ProtectionDomainCacheTable::compute_hash(Handle protection_domain) {
coleenp@12855 36 // Identity hash can safepoint, so keep protection domain in a Handle.
coleenp@12855 37 return (unsigned int)(protection_domain->identity_hash());
coleenp@12855 38 }
coleenp@12855 39
coleenp@12855 40 int ProtectionDomainCacheTable::index_for(Handle protection_domain) {
coleenp@12855 41 return hash_to_index(compute_hash(protection_domain));
coleenp@12855 42 }
coleenp@12855 43
coleenp@12855 44 ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size)
coleenp@12855 45 : Hashtable<oop, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
coleenp@12855 46 {
coleenp@12855 47 }
coleenp@12855 48
coleenp@12855 49 void ProtectionDomainCacheTable::unlink(BoolObjectClosure* is_alive) {
coleenp@12855 50 assert(SafepointSynchronize::is_at_safepoint(), "must be");
coleenp@12855 51 for (int i = 0; i < table_size(); ++i) {
coleenp@12855 52 ProtectionDomainCacheEntry** p = bucket_addr(i);
coleenp@12855 53 ProtectionDomainCacheEntry* entry = bucket(i);
coleenp@12855 54 while (entry != NULL) {
coleenp@12855 55 if (is_alive->do_object_b(entry->literal())) {
coleenp@12855 56 p = entry->next_addr();
coleenp@12855 57 } else {
stuefe@13365 58 LogTarget(Debug, protectiondomain) lt;
stuefe@13365 59 if (lt.is_enabled()) {
stuefe@13365 60 LogStream ls(lt);
stuefe@13365 61 ls.print("protection domain unlinked: ");
stuefe@13365 62 entry->literal()->print_value_on(&ls);
stuefe@13365 63 ls.cr();
coleenp@12855 64 }
coleenp@12855 65 *p = entry->next();
coleenp@12855 66 free_entry(entry);
coleenp@12855 67 }
coleenp@12855 68 entry = *p;
coleenp@12855 69 }
coleenp@12855 70 }
coleenp@12855 71 }
coleenp@12855 72
coleenp@12855 73 void ProtectionDomainCacheTable::oops_do(OopClosure* f) {
coleenp@12855 74 for (int index = 0; index < table_size(); index++) {
coleenp@12855 75 for (ProtectionDomainCacheEntry* probe = bucket(index);
coleenp@12855 76 probe != NULL;
coleenp@12855 77 probe = probe->next()) {
coleenp@12855 78 probe->oops_do(f);
coleenp@12855 79 }
coleenp@12855 80 }
coleenp@12855 81 }
coleenp@12855 82
coleenp@12855 83 #ifndef PRODUCT
coleenp@12855 84 void ProtectionDomainCacheTable::print() {
coleenp@12855 85 tty->print_cr("Protection domain cache table (table_size=%d, classes=%d)",
coleenp@12855 86 table_size(), number_of_entries());
coleenp@12855 87 for (int index = 0; index < table_size(); index++) {
coleenp@12855 88 for (ProtectionDomainCacheEntry* probe = bucket(index);
coleenp@12855 89 probe != NULL;
coleenp@12855 90 probe = probe->next()) {
coleenp@12855 91 probe->print();
coleenp@12855 92 }
coleenp@12855 93 }
coleenp@12855 94 }
coleenp@12855 95
coleenp@12855 96 void ProtectionDomainCacheEntry::print() {
coleenp@12855 97 tty->print_cr("entry " PTR_FORMAT " value " PTR_FORMAT " next " PTR_FORMAT,
coleenp@12855 98 p2i(this), p2i(literal()), p2i(next()));
coleenp@12855 99 }
coleenp@12855 100 #endif
coleenp@12855 101
coleenp@12855 102 void ProtectionDomainCacheTable::verify() {
coleenp@13072 103 verify_table<ProtectionDomainCacheEntry>("Protection Domain Table");
coleenp@12855 104 }
coleenp@12855 105
coleenp@12855 106 void ProtectionDomainCacheEntry::verify() {
coleenp@12855 107 guarantee(literal()->is_oop(), "must be an oop");
coleenp@12855 108 }
coleenp@12855 109
coleenp@12855 110 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(Handle protection_domain) {
coleenp@12855 111 unsigned int hash = compute_hash(protection_domain);
coleenp@12855 112 int index = hash_to_index(hash);
coleenp@12855 113
coleenp@12855 114 ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain);
coleenp@12855 115 if (entry == NULL) {
coleenp@12855 116 entry = add_entry(index, hash, protection_domain);
coleenp@12855 117 }
coleenp@12855 118 return entry;
coleenp@12855 119 }
coleenp@12855 120
coleenp@12855 121 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, Handle protection_domain) {
coleenp@12855 122 for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) {
coleenp@12855 123 if (e->protection_domain() == protection_domain()) {
coleenp@12855 124 return e;
coleenp@12855 125 }
coleenp@12855 126 }
coleenp@12855 127
coleenp@12855 128 return NULL;
coleenp@12855 129 }
coleenp@12855 130
coleenp@12855 131 ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, Handle protection_domain) {
coleenp@12855 132 assert_locked_or_safepoint(SystemDictionary_lock);
coleenp@12855 133 assert(index == index_for(protection_domain), "incorrect index?");
coleenp@12855 134 assert(find_entry(index, protection_domain) == NULL, "no double entry");
coleenp@12855 135
coleenp@12855 136 ProtectionDomainCacheEntry* p = new_entry(hash, protection_domain);
coleenp@12855 137 Hashtable<oop, mtClass>::add_entry(index, p);
coleenp@12855 138 return p;
coleenp@12855 139 }