Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/resolutionErrors.cpp
32285 views
/*1* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/resolutionErrors.hpp"26#include "memory/resourceArea.hpp"27#include "oops/oop.inline.hpp"28#include "runtime/handles.inline.hpp"29#include "runtime/safepoint.hpp"30#include "utilities/hashtable.inline.hpp"3132// add new entry to the table33void ResolutionErrorTable::add_entry(int index, unsigned int hash,34constantPoolHandle pool, int cp_index,35Symbol* error, Symbol* message)36{37assert_locked_or_safepoint(SystemDictionary_lock);38assert(!pool.is_null() && error != NULL, "adding NULL obj");3940ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error, message);41add_entry(index, entry);42}4344// find entry in the table45ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,46constantPoolHandle pool, int cp_index)47{48assert_locked_or_safepoint(SystemDictionary_lock);4950for (ResolutionErrorEntry *error_probe = bucket(index);51error_probe != NULL;52error_probe = error_probe->next()) {53if (error_probe->hash() == hash && error_probe->pool() == pool()) {54return error_probe;;55}56}57return NULL;58}5960void ResolutionErrorEntry::set_error(Symbol* e) {61assert(e != NULL, "must set a value");62_error = e;63_error->increment_refcount();64}6566void ResolutionErrorEntry::set_message(Symbol* c) {67assert(c != NULL, "must set a value");68_message = c;69_message->increment_refcount();70}7172// create new error entry73ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,74int cp_index, Symbol* error,75Symbol* message)76{77ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);78entry->set_cp_index(cp_index);79entry->set_error(error);80entry->set_message(message);8182return entry;83}8485void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {86// decrement error refcount87assert(entry->error() != NULL, "error should be set");88entry->error()->decrement_refcount();89entry->message()->decrement_refcount();90Hashtable<ConstantPool*, mtClass>::free_entry(entry);91}929394// create resolution error table95ResolutionErrorTable::ResolutionErrorTable(int table_size)96: Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {97}9899// RedefineClasses support - remove matching entry of a100// constant pool that is going away101void ResolutionErrorTable::delete_entry(ConstantPool* c) {102assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");103for (int i = 0; i < table_size(); i++) {104for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {105ResolutionErrorEntry* entry = *p;106assert(entry->pool() != NULL, "resolution error table is corrupt");107if (entry->pool() == c) {108*p = entry->next();109free_entry(entry);110} else {111p = entry->next_addr();112}113}114}115}116117118// Remove unloaded entries from the table119void ResolutionErrorTable::purge_resolution_errors() {120assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");121for (int i = 0; i < table_size(); i++) {122for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {123ResolutionErrorEntry* entry = *p;124assert(entry->pool() != (ConstantPool*)NULL, "resolution error table is corrupt");125ConstantPool* pool = entry->pool();126assert(pool->pool_holder() != NULL, "Constant pool without a class?");127ClassLoaderData* loader_data =128pool->pool_holder()->class_loader_data();129if (!loader_data->is_unloading()) {130p = entry->next_addr();131} else {132*p = entry->next();133free_entry(entry);134}135}136}137}138139140