duke@435: /* duke@435: * Copyright 2005 Sun Microsystems, Inc. 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: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: # include "incls/_precompiled.incl" duke@435: # include "incls/_resolutionErrors.cpp.incl" duke@435: duke@435: // add new entry to the table duke@435: void ResolutionErrorTable::add_entry(int index, unsigned int hash, duke@435: constantPoolHandle pool, int cp_index, symbolHandle error) duke@435: { duke@435: assert_locked_or_safepoint(SystemDictionary_lock); duke@435: assert(!pool.is_null() && !error.is_null(), "adding NULL obj"); duke@435: duke@435: 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: duke@435: // create new error entry duke@435: ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, constantPoolOop pool, duke@435: int cp_index, symbolOop error) duke@435: { duke@435: ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable::new_entry(hash, pool); duke@435: entry->set_cp_index(cp_index); duke@435: entry->set_error(error); duke@435: duke@435: return entry; duke@435: } duke@435: duke@435: // create resolution error table duke@435: ResolutionErrorTable::ResolutionErrorTable(int table_size) duke@435: : 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"); duke@435: assert(probe->error() != (symbolOop)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: blk->do_oop((oop*)error_addr()); duke@435: } duke@435: duke@435: // We must keep the symbolOop used in the error alive. The constantPoolOop will duke@435: // decide when the entry can be purged. duke@435: void ResolutionErrorTable::always_strong_classes_do(OopClosure* blk) { 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->error() != (symbolOop)NULL, "resolution error table is corrupt"); duke@435: blk->do_oop((oop*)probe->error_addr()); duke@435: } duke@435: } 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: }