duke@435: /* coleenp@4037: * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "classfile/resolutionErrors.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/safepoint.hpp" stefank@2314: #include "utilities/hashtable.inline.hpp" duke@435: duke@435: // add new entry to the table duke@435: void ResolutionErrorTable::add_entry(int index, unsigned int hash, coleenp@2497: constantPoolHandle pool, int cp_index, Symbol* error) duke@435: { duke@435: assert_locked_or_safepoint(SystemDictionary_lock); coleenp@2497: assert(!pool.is_null() && error != NULL, "adding NULL obj"); duke@435: coleenp@2497: ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error); duke@435: add_entry(index, entry); duke@435: } duke@435: duke@435: // find entry in the table duke@435: ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash, duke@435: constantPoolHandle pool, int cp_index) duke@435: { duke@435: assert_locked_or_safepoint(SystemDictionary_lock); duke@435: duke@435: for (ResolutionErrorEntry *error_probe = bucket(index); duke@435: error_probe != NULL; duke@435: error_probe = error_probe->next()) { duke@435: if (error_probe->hash() == hash && error_probe->pool() == pool()) { duke@435: return error_probe;; duke@435: } duke@435: } duke@435: return NULL; duke@435: } duke@435: coleenp@2497: void ResolutionErrorEntry::set_error(Symbol* e) { coleenp@2497: assert(e == NULL || _error == NULL, "cannot reset error"); coleenp@2497: _error = e; coleenp@2497: if (_error != NULL) _error->increment_refcount(); coleenp@2497: } coleenp@2497: duke@435: // create new error entry coleenp@4037: ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool, coleenp@2497: int cp_index, Symbol* error) duke@435: { coleenp@4037: ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable::new_entry(hash, pool); duke@435: entry->set_cp_index(cp_index); coleenp@2497: NOT_PRODUCT(entry->set_error(NULL);) duke@435: entry->set_error(error); duke@435: duke@435: return entry; duke@435: } duke@435: coleenp@2497: void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) { coleenp@2497: // decrement error refcount coleenp@2497: assert(entry->error() != NULL, "error should be set"); coleenp@2497: entry->error()->decrement_refcount(); coleenp@4037: Hashtable::free_entry(entry); coleenp@2497: } coleenp@2497: coleenp@2497: duke@435: // create resolution error table duke@435: ResolutionErrorTable::ResolutionErrorTable(int table_size) coleenp@4037: : Hashtable(table_size, sizeof(ResolutionErrorEntry)) { duke@435: } duke@435: coleenp@4037: // RedefineClasses support - remove matching entry of a coleenp@4037: // constant pool that is going away coleenp@4037: void ResolutionErrorTable::delete_entry(ConstantPool* c) { coleenp@4037: assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); duke@435: for (int i = 0; i < table_size(); i++) { coleenp@4037: for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) { coleenp@4037: ResolutionErrorEntry* entry = *p; coleenp@4037: assert(entry->pool() != NULL, "resolution error table is corrupt"); coleenp@4037: if (entry->pool() == c) { coleenp@4037: *p = entry->next(); coleenp@4037: free_entry(entry); coleenp@4037: } else { coleenp@4037: p = entry->next_addr(); coleenp@4037: } duke@435: } duke@435: } duke@435: } duke@435: duke@435: duke@435: // Remove unloaded entries from the table coleenp@4037: void ResolutionErrorTable::purge_resolution_errors() { jcoomes@1844: assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); duke@435: for (int i = 0; i < table_size(); i++) { duke@435: for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) { duke@435: ResolutionErrorEntry* entry = *p; coleenp@4037: assert(entry->pool() != (ConstantPool*)NULL, "resolution error table is corrupt"); coleenp@4037: ConstantPool* pool = entry->pool(); coleenp@4037: assert(pool->pool_holder() != NULL, "Constant pool without a class?"); coleenp@4037: ClassLoaderData* loader_data = coleenp@4037: pool->pool_holder()->class_loader_data(); coleenp@4037: if (!loader_data->is_unloading()) { duke@435: p = entry->next_addr(); duke@435: } else { duke@435: *p = entry->next(); duke@435: free_entry(entry); duke@435: } duke@435: } duke@435: } duke@435: }