src/share/vm/classfile/resolutionErrors.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
child 10015
eb7ce841ccec
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "classfile/resolutionErrors.hpp"
aoqi@0 27 #include "memory/resourceArea.hpp"
aoqi@0 28 #include "oops/oop.inline.hpp"
aoqi@0 29 #include "runtime/handles.inline.hpp"
aoqi@0 30 #include "runtime/safepoint.hpp"
aoqi@0 31 #include "utilities/hashtable.inline.hpp"
aoqi@0 32
aoqi@0 33 // add new entry to the table
aoqi@0 34 void ResolutionErrorTable::add_entry(int index, unsigned int hash,
aoqi@0 35 constantPoolHandle pool, int cp_index, Symbol* error)
aoqi@0 36 {
aoqi@0 37 assert_locked_or_safepoint(SystemDictionary_lock);
aoqi@0 38 assert(!pool.is_null() && error != NULL, "adding NULL obj");
aoqi@0 39
aoqi@0 40 ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error);
aoqi@0 41 add_entry(index, entry);
aoqi@0 42 }
aoqi@0 43
aoqi@0 44 // find entry in the table
aoqi@0 45 ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,
aoqi@0 46 constantPoolHandle pool, int cp_index)
aoqi@0 47 {
aoqi@0 48 assert_locked_or_safepoint(SystemDictionary_lock);
aoqi@0 49
aoqi@0 50 for (ResolutionErrorEntry *error_probe = bucket(index);
aoqi@0 51 error_probe != NULL;
aoqi@0 52 error_probe = error_probe->next()) {
aoqi@0 53 if (error_probe->hash() == hash && error_probe->pool() == pool()) {
aoqi@0 54 return error_probe;;
aoqi@0 55 }
aoqi@0 56 }
aoqi@0 57 return NULL;
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 void ResolutionErrorEntry::set_error(Symbol* e) {
aoqi@0 61 assert(e == NULL || _error == NULL, "cannot reset error");
aoqi@0 62 _error = e;
aoqi@0 63 if (_error != NULL) _error->increment_refcount();
aoqi@0 64 }
aoqi@0 65
aoqi@0 66 // create new error entry
aoqi@0 67 ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
aoqi@0 68 int cp_index, Symbol* error)
aoqi@0 69 {
aoqi@0 70 ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
aoqi@0 71 entry->set_cp_index(cp_index);
aoqi@0 72 NOT_PRODUCT(entry->set_error(NULL);)
aoqi@0 73 entry->set_error(error);
aoqi@0 74
aoqi@0 75 return entry;
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
aoqi@0 79 // decrement error refcount
aoqi@0 80 assert(entry->error() != NULL, "error should be set");
aoqi@0 81 entry->error()->decrement_refcount();
aoqi@0 82 Hashtable<ConstantPool*, mtClass>::free_entry(entry);
aoqi@0 83 }
aoqi@0 84
aoqi@0 85
aoqi@0 86 // create resolution error table
aoqi@0 87 ResolutionErrorTable::ResolutionErrorTable(int table_size)
aoqi@0 88 : Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 // RedefineClasses support - remove matching entry of a
aoqi@0 92 // constant pool that is going away
aoqi@0 93 void ResolutionErrorTable::delete_entry(ConstantPool* c) {
aoqi@0 94 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
aoqi@0 95 for (int i = 0; i < table_size(); i++) {
aoqi@0 96 for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
aoqi@0 97 ResolutionErrorEntry* entry = *p;
aoqi@0 98 assert(entry->pool() != NULL, "resolution error table is corrupt");
aoqi@0 99 if (entry->pool() == c) {
aoqi@0 100 *p = entry->next();
aoqi@0 101 free_entry(entry);
aoqi@0 102 } else {
aoqi@0 103 p = entry->next_addr();
aoqi@0 104 }
aoqi@0 105 }
aoqi@0 106 }
aoqi@0 107 }
aoqi@0 108
aoqi@0 109
aoqi@0 110 // Remove unloaded entries from the table
aoqi@0 111 void ResolutionErrorTable::purge_resolution_errors() {
aoqi@0 112 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
aoqi@0 113 for (int i = 0; i < table_size(); i++) {
aoqi@0 114 for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
aoqi@0 115 ResolutionErrorEntry* entry = *p;
aoqi@0 116 assert(entry->pool() != (ConstantPool*)NULL, "resolution error table is corrupt");
aoqi@0 117 ConstantPool* pool = entry->pool();
aoqi@0 118 assert(pool->pool_holder() != NULL, "Constant pool without a class?");
aoqi@0 119 ClassLoaderData* loader_data =
aoqi@0 120 pool->pool_holder()->class_loader_data();
aoqi@0 121 if (!loader_data->is_unloading()) {
aoqi@0 122 p = entry->next_addr();
aoqi@0 123 } else {
aoqi@0 124 *p = entry->next();
aoqi@0 125 free_entry(entry);
aoqi@0 126 }
aoqi@0 127 }
aoqi@0 128 }
aoqi@0 129 }

mercurial