duke@435: /* trims@2708: * Copyright (c) 2005, 2011, 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 duke@435: ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, constantPoolOop pool, coleenp@2497: int cp_index, Symbol* error) duke@435: { coleenp@2497: 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@2497: Hashtable::free_entry(entry); coleenp@2497: } coleenp@2497: coleenp@2497: duke@435: // create resolution error table duke@435: ResolutionErrorTable::ResolutionErrorTable(int table_size) coleenp@2497: : Hashtable(table_size, sizeof(ResolutionErrorEntry)) { duke@435: } duke@435: duke@435: // GC support duke@435: void ResolutionErrorTable::oops_do(OopClosure* f) { duke@435: for (int i = 0; i < table_size(); i++) { duke@435: for (ResolutionErrorEntry* probe = bucket(i); duke@435: probe != NULL; duke@435: probe = probe->next()) { duke@435: assert(probe->pool() != (constantPoolOop)NULL, "resolution error table is corrupt"); coleenp@2497: assert(probe->error() != (Symbol*)NULL, "resolution error table is corrupt"); duke@435: probe->oops_do(f); duke@435: } duke@435: } duke@435: } duke@435: duke@435: // GC support duke@435: void ResolutionErrorEntry::oops_do(OopClosure* blk) { duke@435: blk->do_oop((oop*)pool_addr()); duke@435: } duke@435: duke@435: // Remove unloaded entries from the table duke@435: void ResolutionErrorTable::purge_resolution_errors(BoolObjectClosure* is_alive) { 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; duke@435: assert(entry->pool() != (constantPoolOop)NULL, "resolution error table is corrupt"); duke@435: constantPoolOop pool = entry->pool(); duke@435: if (is_alive->do_object_b(pool)) { 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: }